2003-10-11 12:29:40 -04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2002 Light Weight Java Game Library Project
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* * Neither the name of 'Light Weight Java Game Library' nor the names of
|
|
|
|
* 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>
|
2003-12-15 06:49:17 -05:00
|
|
|
#include "org_lwjgl_Sys.h"
|
|
|
|
|
2003-10-29 11:21:42 -05:00
|
|
|
// Must be x * max_event_size + 1
|
|
|
|
#define EVENT_BUFFER_SIZE (25 * 4 + 1)
|
2003-10-11 12:29:40 -04:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
unsigned char input_event_buffer[EVENT_BUFFER_SIZE];
|
|
|
|
|
|
|
|
int list_start;
|
|
|
|
int list_end;
|
|
|
|
} event_queue_t;
|
|
|
|
|
2004-03-27 09:09:55 -05:00
|
|
|
extern bool isDebugEnabled(void);
|
|
|
|
extern jstring getVersionString(JNIEnv *env);
|
2003-10-11 12:29:40 -04:00
|
|
|
extern void initEventQueue(event_queue_t *event_queue);
|
2004-03-26 16:11:20 -05:00
|
|
|
extern int copyEvents(event_queue_t *event_queue, unsigned char *output_event_buffer, int buffer_size, int event_size);
|
2003-10-11 12:29:40 -04:00
|
|
|
extern void putEventElement(event_queue_t *queue, unsigned char byte);
|
|
|
|
extern unsigned char *getOutputList(event_queue_t *queue);
|
2004-03-26 16:11:20 -05:00
|
|
|
//extern int getEventBufferSize(event_queue_t *event_queue);
|
2003-10-11 12:29:40 -04:00
|
|
|
extern void throwException(JNIEnv *env, const char *msg);
|
2003-10-22 06:57:19 -04:00
|
|
|
extern void throwOpenALException(JNIEnv * env, const char * err);
|
2004-05-23 09:50:08 -04:00
|
|
|
extern void throwFMODException(JNIEnv * env, const char * err);
|
2003-12-20 17:03:25 -05:00
|
|
|
extern void setDebugEnabled(bool enable);
|
|
|
|
extern void printfDebug(const char *format, ...);
|
2004-03-11 16:30:48 -05:00
|
|
|
extern bool getBooleanProperty(JNIEnv *env, const char* propertyName);
|
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-01-05 17:43:42 -05:00
|
|
|
if (buffer == NULL)
|
|
|
|
return NULL;
|
|
|
|
else
|
2004-01-20 05:11:02 -05:00
|
|
|
return (void *)((char *)env->GetDirectBufferAddress(buffer) + offset);
|
2004-01-05 17:43:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline jobject safeNewBuffer(JNIEnv *env, void *p, int size) {
|
|
|
|
if (p == NULL)
|
|
|
|
return NULL;
|
|
|
|
else
|
|
|
|
return env->NewDirectByteBuffer(p, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline const void *offsetToPointer(jint offset) {
|
|
|
|
return (const char *)NULL + offset;
|
|
|
|
}
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
extern void doExtension(JNIEnv *env, jobject ext_set, const char *method_name, const char *ext);
|
|
|
|
extern jclass ext_ResetClass(JNIEnv *env, const char *class_name);
|
2004-03-09 06:03:10 -05:00
|
|
|
extern bool ext_InitializeClass(JNIEnv *env, jclass clazz, jobject ext_set, const char *ext_name, 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
|
|
|
|
2003-10-11 12:29:40 -04:00
|
|
|
#endif
|