2003-10-11 12:29:40 -04:00
|
|
|
/*
|
2004-06-12 16:28:34 -04:00
|
|
|
* Copyright (c) 2002-2004 LWJGL Project
|
2003-10-11 12:29:40 -04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
2004-06-12 16:28:34 -04:00
|
|
|
* * Neither the name of 'LWJGL' nor the names of
|
2003-10-11 12:29:40 -04:00
|
|
|
* its contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* @author elias_naur <elias_naur@users.sourceforge.net>
|
|
|
|
* @version $Revision$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _COMMON_TOOLS_H
|
|
|
|
#define _COMMON_TOOLS_H
|
|
|
|
|
|
|
|
#include <jni.h>
|
2004-11-14 06:39:54 -05:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2003-12-15 06:49:17 -05:00
|
|
|
|
2004-09-27 09:20:27 -04:00
|
|
|
#define EVENT_BUFFER_SIZE 256
|
2004-07-02 15:02:00 -04:00
|
|
|
#define ATTRIB_LIST_SIZE (256)
|
2003-10-11 12:29:40 -04:00
|
|
|
|
|
|
|
typedef struct {
|
2004-09-27 09:20:27 -04:00
|
|
|
int event_size;
|
|
|
|
int position;
|
|
|
|
int limit;
|
2004-09-22 07:08:21 -04:00
|
|
|
jint input_event_buffer[EVENT_BUFFER_SIZE];
|
2003-10-11 12:29:40 -04:00
|
|
|
} event_queue_t;
|
|
|
|
|
2004-07-02 15:02:00 -04:00
|
|
|
typedef struct {
|
|
|
|
int current_index;
|
|
|
|
int attribs[ATTRIB_LIST_SIZE];
|
|
|
|
} attrib_list_t;
|
|
|
|
|
2004-11-02 10:51:09 -05:00
|
|
|
#ifndef __cplusplus
|
|
|
|
#ifndef bool
|
2004-11-02 09:43:16 -05:00
|
|
|
typedef enum {false, true} bool;
|
2004-09-10 04:13:56 -04:00
|
|
|
#endif
|
2004-11-02 10:51:09 -05:00
|
|
|
#endif
|
2004-09-10 04:13:56 -04:00
|
|
|
|
2004-09-10 05:56:26 -04:00
|
|
|
#ifdef _WIN32
|
|
|
|
#define inline __inline
|
|
|
|
#endif
|
2003-10-11 12:29:40 -04:00
|
|
|
|
2004-01-20 05:11:02 -05:00
|
|
|
static inline void * safeGetBufferAddress(JNIEnv *env, jobject buffer, int offset) {
|
2004-09-10 05:56:26 -04:00
|
|
|
if (buffer != NULL) {
|
|
|
|
#ifdef __cplusplus
|
|
|
|
return (void *)((char *)env->GetDirectBufferAddress(buffer) + offset);
|
|
|
|
#else
|
2004-09-10 04:13:56 -04:00
|
|
|
return (void *)((char *)(*env)->GetDirectBufferAddress(env, buffer) + offset);
|
2004-09-10 05:56:26 -04:00
|
|
|
#endif
|
|
|
|
} else
|
|
|
|
return NULL;
|
2004-01-05 17:43:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline jobject safeNewBuffer(JNIEnv *env, void *p, int size) {
|
2004-09-10 05:56:26 -04:00
|
|
|
if (p != NULL) {
|
|
|
|
#ifdef __cplusplus
|
|
|
|
return env->NewDirectByteBuffer(p, size);
|
|
|
|
#else
|
2004-09-10 04:13:56 -04:00
|
|
|
return (*env)->NewDirectByteBuffer(env, p, size);
|
2004-09-10 05:56:26 -04:00
|
|
|
#endif
|
|
|
|
} else
|
|
|
|
return NULL;
|
2004-01-05 17:43:42 -05:00
|
|
|
}
|
|
|
|
|
2005-01-13 07:14:10 -05:00
|
|
|
static inline void *offsetToPointer(jint offset) {
|
|
|
|
return (char *)NULL + offset;
|
2004-01-05 17:43:42 -05:00
|
|
|
}
|
|
|
|
|
2004-03-09 04:25:10 -05:00
|
|
|
typedef void *(* ExtGetProcAddressPROC) (const char *func_name);
|
|
|
|
typedef struct {
|
|
|
|
char *method_name;
|
|
|
|
char *signature;
|
|
|
|
void *method_pointer;
|
|
|
|
|
|
|
|
char *ext_function_name;
|
|
|
|
void **ext_function_pointer;
|
|
|
|
} JavaMethodAndExtFunction;
|
|
|
|
|
2004-03-11 07:38:13 -05:00
|
|
|
typedef struct {
|
|
|
|
char *ext_function_name;
|
|
|
|
void **ext_function_pointer;
|
|
|
|
} ExtFunction;
|
|
|
|
|
2004-03-09 04:25:10 -05:00
|
|
|
#define NUMFUNCTIONS(x) (sizeof(x)/sizeof(JavaMethodAndExtFunction));
|
|
|
|
|
2004-09-10 05:56:26 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2004-11-02 09:43:16 -05:00
|
|
|
extern JavaVM *getJVM();
|
2004-09-10 05:56:26 -04:00
|
|
|
extern void initAttribList(attrib_list_t *list);
|
|
|
|
extern void putAttrib(attrib_list_t *list, int attrib);
|
|
|
|
|
|
|
|
extern bool isDebugEnabled(void);
|
|
|
|
extern jstring getVersionString(JNIEnv *env);
|
2004-09-27 09:20:27 -04:00
|
|
|
extern void initEventQueue(event_queue_t *event_queue, int event_size);
|
|
|
|
extern int copyEvents(event_queue_t *event_queue, jint *output_event_buffer, int buffer_size);
|
|
|
|
extern bool putEvent(event_queue_t *queue, jint *event);
|
2005-01-11 10:22:12 -05:00
|
|
|
extern void throwGeneralException(JNIEnv * env, const char *exception_name, const char * err);
|
2004-09-10 05:56:26 -04:00
|
|
|
extern void throwException(JNIEnv *env, const char *msg);
|
|
|
|
extern void throwOpenALException(JNIEnv * env, const char * err);
|
|
|
|
extern void throwFMODException(JNIEnv * env, const char * err);
|
|
|
|
extern void setDebugEnabled(bool enable);
|
2004-12-11 14:44:53 -05:00
|
|
|
extern void printfDebugJava(JNIEnv *env, const char *format, ...);
|
2004-09-10 05:56:26 -04:00
|
|
|
extern void printfDebug(const char *format, ...);
|
|
|
|
extern bool getBooleanProperty(JNIEnv *env, const char* propertyName);
|
2004-11-13 16:06:38 -05:00
|
|
|
extern char * GetStringNativeChars(JNIEnv *env, jstring jstr);
|
2004-11-14 05:42:19 -05:00
|
|
|
extern jstring NewStringNative(JNIEnv *env, const char *str);
|
2004-09-10 05:56:26 -04:00
|
|
|
|
2004-07-04 09:14:06 -04:00
|
|
|
extern void ext_InitializeClass(JNIEnv *env, jclass clazz, ExtGetProcAddressPROC gpa, int num_functions, JavaMethodAndExtFunction *functions);
|
2004-03-11 07:38:13 -05:00
|
|
|
extern bool ext_InitializeFunctions(ExtGetProcAddressPROC gpa, int num_functions, ExtFunction *functions);
|
2004-03-09 04:25:10 -05:00
|
|
|
|
2004-09-10 05:56:26 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
2003-10-11 12:29:40 -04:00
|
|
|
#endif
|
2004-09-10 05:56:26 -04:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|