new
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*.DS_Store
|
||||
|
||||
BIN
bin/crashpad_handler
Executable file
BIN
bin/crashpad_handler
Executable file
Binary file not shown.
361
include/plib/fnt.h
Normal file
361
include/plib/fnt.h
Normal file
@@ -0,0 +1,361 @@
|
||||
/*
|
||||
PLIB - A Suite of Portable Game Libraries
|
||||
Copyright (C) 1998,2002 Steve Baker
|
||||
|
||||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information visit http://plib.sourceforge.net
|
||||
|
||||
$Id: fnt.h 1923 2004-04-06 12:53:17Z sjbaker $
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _FNT_H_
|
||||
#define _FNT_H_ 1
|
||||
|
||||
#include <stdio.h>
|
||||
#include "sg.h"
|
||||
|
||||
#ifdef UL_MAC_OSX
|
||||
# include <OpenGL/gl.h>
|
||||
#else
|
||||
# include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
|
||||
#define FNTMAX_CHAR 256
|
||||
#define FNT_TRUE 1
|
||||
#define FNT_FALSE 0
|
||||
|
||||
|
||||
class fntFont
|
||||
{
|
||||
public:
|
||||
fntFont () ;
|
||||
|
||||
virtual ~fntFont () ;
|
||||
|
||||
virtual void getBBox ( const char *s, float pointsize, float italic,
|
||||
float *left, float *right,
|
||||
float *bot , float *top ) = 0 ;
|
||||
virtual void putch ( sgVec3 curpos, float pointsize, float italic, char c ) = 0 ;
|
||||
virtual void puts ( sgVec3 curpos, float pointsize, float italic, const char *s ) = 0 ;
|
||||
virtual void begin () = 0 ;
|
||||
virtual void end () = 0 ;
|
||||
|
||||
virtual int load ( const char *fname, GLenum mag = GL_NEAREST,
|
||||
GLenum min = GL_LINEAR_MIPMAP_LINEAR ) = 0 ;
|
||||
|
||||
virtual void setFixedPitch ( int fix ) = 0 ;
|
||||
virtual int isFixedPitch () const = 0 ;
|
||||
|
||||
virtual void setWidth ( float w ) = 0 ;
|
||||
virtual void setGap ( float g ) = 0 ;
|
||||
|
||||
virtual float getWidth () const = 0 ;
|
||||
virtual float getGap () const = 0 ;
|
||||
|
||||
virtual int hasGlyph ( char c ) const = 0 ;
|
||||
} ;
|
||||
|
||||
|
||||
class fntTexFont : public fntFont
|
||||
{
|
||||
private:
|
||||
GLuint texture ;
|
||||
int bound ;
|
||||
int fixed_pitch ;
|
||||
|
||||
float width ; /* The width of a character in fixed-width mode */
|
||||
float gap ; /* Set the gap between characters */
|
||||
|
||||
int exists [ FNTMAX_CHAR ] ; /* TRUE if character exists in tex-map */
|
||||
|
||||
/*
|
||||
The quadrilaterals that describe the characters
|
||||
in the font are drawn with the following texture
|
||||
and spatial coordinates. The texture coordinates
|
||||
are in (S,T) space, with (0,0) at the bottom left
|
||||
of the image and (1,1) at the top-right.
|
||||
|
||||
The spatial coordinates are relative to the current
|
||||
'cursor' position. They should be scaled such that
|
||||
1.0 represent the height of a capital letter. Hence,
|
||||
characters like 'y' which have a descender will be
|
||||
given a negative v_bot. Most capitals will have
|
||||
v_bot==0.0 and v_top==1.0.
|
||||
*/
|
||||
|
||||
/* Nominal baseline widths */
|
||||
|
||||
float widths [ FNTMAX_CHAR ] ;
|
||||
|
||||
/* Texture coordinates */
|
||||
|
||||
float t_top [ FNTMAX_CHAR ] ; /* Top edge of each character [0..1] */
|
||||
float t_bot [ FNTMAX_CHAR ] ; /* Bottom edge of each character [0..1] */
|
||||
float t_left [ FNTMAX_CHAR ] ; /* Left edge of each character [0..1] */
|
||||
float t_right [ FNTMAX_CHAR ] ; /* Right edge of each character [0..1] */
|
||||
|
||||
/* Vertex coordinates. */
|
||||
|
||||
float v_top [ FNTMAX_CHAR ] ;
|
||||
float v_bot [ FNTMAX_CHAR ] ;
|
||||
float v_left [ FNTMAX_CHAR ] ;
|
||||
float v_right [ FNTMAX_CHAR ] ;
|
||||
|
||||
void bind_texture ()
|
||||
{
|
||||
glEnable ( GL_TEXTURE_2D ) ;
|
||||
#ifdef GL_VERSION_1_1
|
||||
glBindTexture ( GL_TEXTURE_2D, texture ) ;
|
||||
#else
|
||||
/* For ancient SGI machines */
|
||||
glBindTextureEXT ( GL_TEXTURE_2D, texture ) ;
|
||||
#endif
|
||||
}
|
||||
|
||||
float low_putch ( sgVec3 curpos, float pointsize, float italic, char c ) ;
|
||||
|
||||
int loadTXF ( const char *fname, GLenum mag = GL_NEAREST,
|
||||
GLenum min = GL_LINEAR_MIPMAP_LINEAR ) ;
|
||||
public:
|
||||
|
||||
fntTexFont ()
|
||||
{
|
||||
bound = FNT_FALSE ;
|
||||
fixed_pitch = FNT_TRUE ;
|
||||
texture = 0 ;
|
||||
width = 1.0f ;
|
||||
gap = 0.1f ;
|
||||
|
||||
memset ( exists, FNT_FALSE, FNTMAX_CHAR * sizeof(int) ) ;
|
||||
}
|
||||
|
||||
fntTexFont ( const char *fname, GLenum mag = GL_NEAREST,
|
||||
GLenum min = GL_LINEAR_MIPMAP_LINEAR ) : fntFont ()
|
||||
{
|
||||
bound = FNT_FALSE ;
|
||||
fixed_pitch = FNT_TRUE ;
|
||||
texture = 0 ;
|
||||
width = 1.0f ;
|
||||
gap = 0.1f ;
|
||||
|
||||
memset ( exists, FNT_FALSE, FNTMAX_CHAR * sizeof(int) ) ;
|
||||
load ( fname, mag, min ) ;
|
||||
}
|
||||
|
||||
~fntTexFont ()
|
||||
{
|
||||
if ( texture != 0 )
|
||||
{
|
||||
#ifdef GL_VERSION_1_1
|
||||
glDeleteTextures ( 1, &texture ) ;
|
||||
#else
|
||||
/* For ancient SGI machines */
|
||||
glDeleteTexturesEXT ( 1, &texture ) ;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
int load ( const char *fname, GLenum mag = GL_NEAREST,
|
||||
GLenum min = GL_LINEAR_MIPMAP_LINEAR ) ;
|
||||
|
||||
void setFixedPitch ( int fix ) { fixed_pitch = fix ; }
|
||||
int isFixedPitch () const { return fixed_pitch ; }
|
||||
|
||||
void setWidth ( float w ) { width = w ; }
|
||||
void setGap ( float g ) { gap = g ; }
|
||||
|
||||
float getWidth () const { return width ; }
|
||||
float getGap () const { return gap ; }
|
||||
|
||||
|
||||
void setGlyph ( char c, float wid,
|
||||
float tex_left, float tex_right,
|
||||
float tex_bot , float tex_top ,
|
||||
float vtx_left, float vtx_right,
|
||||
float vtx_bot , float vtx_top ) ;
|
||||
void setGlyph ( char c,
|
||||
float tex_left, float tex_right,
|
||||
float tex_bot , float tex_top ,
|
||||
float vtx_left, float vtx_right,
|
||||
float vtx_bot , float vtx_top ) /* deprecated */
|
||||
{
|
||||
setGlyph ( c, vtx_right,
|
||||
tex_left, tex_right, tex_bot, tex_top,
|
||||
vtx_left, vtx_right, vtx_bot, vtx_top ) ;
|
||||
}
|
||||
|
||||
int getGlyph ( char c, float* wid,
|
||||
float *tex_left = NULL, float *tex_right = NULL,
|
||||
float *tex_bot = NULL, float *tex_top = NULL,
|
||||
float *vtx_left = NULL, float *vtx_right = NULL,
|
||||
float *vtx_bot = NULL, float *vtx_top = NULL) ;
|
||||
int getGlyph ( char c,
|
||||
float *tex_left = NULL, float *tex_right = NULL,
|
||||
float *tex_bot = NULL, float *tex_top = NULL,
|
||||
float *vtx_left = NULL, float *vtx_right = NULL,
|
||||
float *vtx_bot = NULL, float *vtx_top = NULL) /* deprecated */
|
||||
{
|
||||
return getGlyph ( c, NULL,
|
||||
tex_left, tex_right, tex_bot, tex_top,
|
||||
vtx_left, vtx_right, vtx_bot, vtx_top ) ;
|
||||
}
|
||||
|
||||
int hasGlyph ( char c ) const { return exists[ (GLubyte) c ] ; }
|
||||
|
||||
void getBBox ( const char *s, float pointsize, float italic,
|
||||
float *left, float *right,
|
||||
float *bot , float *top ) ;
|
||||
|
||||
void begin ()
|
||||
{
|
||||
bind_texture () ;
|
||||
bound = FNT_TRUE ;
|
||||
}
|
||||
|
||||
void end ()
|
||||
{
|
||||
bound = FNT_FALSE ;
|
||||
}
|
||||
|
||||
void puts ( sgVec3 curpos, float pointsize, float italic, const char *s ) ;
|
||||
|
||||
void putch ( sgVec3 curpos, float pointsize, float italic, char c )
|
||||
{
|
||||
if ( ! bound )
|
||||
bind_texture () ;
|
||||
|
||||
low_putch ( curpos, pointsize, italic, c ) ;
|
||||
}
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
class fntBitmapFont : public fntFont
|
||||
{
|
||||
protected:
|
||||
|
||||
const GLubyte **data;
|
||||
int first;
|
||||
int count;
|
||||
int height;
|
||||
float xorig, yorig;
|
||||
int fix;
|
||||
float wid, gap;
|
||||
|
||||
public:
|
||||
|
||||
// data is a null-terminated list of glyph images:
|
||||
// data[i][0] - image width
|
||||
// data[i][1..n] - packed bitmap
|
||||
|
||||
fntBitmapFont ( const GLubyte **data, int first, int height,
|
||||
float xorig, float yorig ) ;
|
||||
|
||||
virtual ~fntBitmapFont () ;
|
||||
|
||||
virtual void getBBox ( const char *s, float pointsize, float italic,
|
||||
float *left, float *right,
|
||||
float *bot , float *top ) ;
|
||||
|
||||
virtual void putch ( sgVec3 curpos, float pointsize, float italic, char c ) ;
|
||||
virtual void puts ( sgVec3 curpos, float pointsize, float italic, const char *s ) ;
|
||||
|
||||
virtual void begin () ;
|
||||
virtual void end () ;
|
||||
|
||||
virtual int load ( const char *fname, GLenum mag, GLenum min ) { return -1; }
|
||||
|
||||
virtual void setFixedPitch ( int f ) { fix = f; }
|
||||
virtual int isFixedPitch () const { return fix; }
|
||||
|
||||
virtual void setWidth ( float w ) { wid = w; }
|
||||
virtual void setGap ( float g ) { gap = g; }
|
||||
|
||||
virtual float getWidth () const { return wid; }
|
||||
virtual float getGap () const { return gap; }
|
||||
|
||||
virtual int hasGlyph ( char c ) const ;
|
||||
};
|
||||
|
||||
|
||||
/* Builtin Bitmap Fonts */
|
||||
|
||||
#define FNT_BITMAP_8_BY_13 0
|
||||
#define FNT_BITMAP_9_BY_15 1
|
||||
#define FNT_BITMAP_HELVETICA_10 2
|
||||
#define FNT_BITMAP_HELVETICA_12 3
|
||||
#define FNT_BITMAP_HELVETICA_18 4
|
||||
#define FNT_BITMAP_TIMES_ROMAN_10 5
|
||||
#define FNT_BITMAP_TIMES_ROMAN_24 6
|
||||
|
||||
fntBitmapFont *fntGetBitmapFont(int id);
|
||||
|
||||
|
||||
|
||||
class fntRenderer
|
||||
{
|
||||
fntFont *font ;
|
||||
|
||||
sgVec3 curpos ;
|
||||
|
||||
float pointsize ;
|
||||
float italic ;
|
||||
|
||||
public:
|
||||
fntRenderer ()
|
||||
{
|
||||
start2f ( 0.0f, 0.0f ) ;
|
||||
font = NULL ;
|
||||
pointsize = 10 ;
|
||||
italic = 0 ;
|
||||
}
|
||||
|
||||
void start3fv ( sgVec3 pos ) { sgCopyVec3 ( curpos, pos ) ; }
|
||||
void start2fv ( sgVec2 pos ) { sgCopyVec2 ( curpos, pos ) ; curpos[2]=0.0f ; }
|
||||
void start2f ( float x, float y ) { sgSetVec3 ( curpos, x, y, 0.0f ) ; }
|
||||
void start3f ( float x, float y, float z ) { sgSetVec3 ( curpos, x, y, z ) ; }
|
||||
|
||||
void getCursor ( float *x, float *y, float *z ) const
|
||||
{
|
||||
if ( x != NULL ) *x = curpos [ 0 ] ;
|
||||
if ( y != NULL ) *y = curpos [ 1 ] ;
|
||||
if ( z != NULL ) *z = curpos [ 2 ] ;
|
||||
}
|
||||
|
||||
void setFont ( fntFont *f ) { font = f ; }
|
||||
fntFont *getFont () const { return font ; }
|
||||
|
||||
void setSlant ( float i ) { italic = i ; }
|
||||
void setPointSize ( float p ) { pointsize = p ; }
|
||||
|
||||
float getSlant () const { return italic ; }
|
||||
float getPointSize () const { return pointsize ; }
|
||||
|
||||
void begin () { font->begin () ; }
|
||||
void end () { font->end () ; }
|
||||
|
||||
void putch ( char c ) { font->putch ( curpos, pointsize, italic, c ) ; }
|
||||
void puts ( const char *s ) { font->puts ( curpos, pointsize, italic, s ) ; }
|
||||
} ;
|
||||
|
||||
|
||||
void fntInit () ;
|
||||
|
||||
#endif
|
||||
|
||||
98
include/plib/js.h
Normal file
98
include/plib/js.h
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
PLIB - A Suite of Portable Game Libraries
|
||||
Copyright (C) 1998,2002 Steve Baker
|
||||
|
||||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information visit http://plib.sourceforge.net
|
||||
|
||||
$Id: js.h 2067 2006-01-30 07:36:01Z bram $
|
||||
*/
|
||||
|
||||
#ifndef __INCLUDED_JS_H__
|
||||
#define __INCLUDED_JS_H__ 1
|
||||
#define JS_NEW
|
||||
|
||||
#include "ul.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h> // -dw- for memcpy
|
||||
|
||||
#define _JS_MAX_AXES 16
|
||||
#define _JS_MAX_BUTTONS 32
|
||||
#define _JS_MAX_HATS 4
|
||||
|
||||
#define JS_TRUE 1
|
||||
#define JS_FALSE 0
|
||||
|
||||
|
||||
class jsJoystick
|
||||
{
|
||||
int id ;
|
||||
protected:
|
||||
struct os_specific_s *os ;
|
||||
friend struct os_specific_s ;
|
||||
int error ;
|
||||
char name [ 128 ] ;
|
||||
int num_axes ;
|
||||
int num_buttons ;
|
||||
|
||||
float dead_band [ _JS_MAX_AXES ] ;
|
||||
float saturate [ _JS_MAX_AXES ] ;
|
||||
float center [ _JS_MAX_AXES ] ;
|
||||
float max [ _JS_MAX_AXES ] ;
|
||||
float min [ _JS_MAX_AXES ] ;
|
||||
|
||||
void open () ;
|
||||
void close () ;
|
||||
|
||||
float fudge_axis ( float value, int axis ) const ;
|
||||
|
||||
public:
|
||||
|
||||
jsJoystick ( int ident = 0 ) ;
|
||||
~jsJoystick () { close () ; }
|
||||
|
||||
const char* getName () const { return name ; }
|
||||
int getNumAxes () const { return num_axes ; }
|
||||
int getNumButtons () const { return num_buttons; }
|
||||
int notWorking () const { return error ; }
|
||||
void setError () { error = JS_TRUE ; }
|
||||
|
||||
float getDeadBand ( int axis ) const { return dead_band [ axis ] ; }
|
||||
void setDeadBand ( int axis, float db ) { dead_band [ axis ] = db ; }
|
||||
|
||||
float getSaturation ( int axis ) const { return saturate [ axis ] ; }
|
||||
void setSaturation ( int axis, float st ) { saturate [ axis ] = st ; }
|
||||
|
||||
void setMinRange ( float *axes ) { memcpy ( min , axes, num_axes * sizeof(float) ) ; }
|
||||
void setMaxRange ( float *axes ) { memcpy ( max , axes, num_axes * sizeof(float) ) ; }
|
||||
void setCenter ( float *axes ) { memcpy ( center, axes, num_axes * sizeof(float) ) ; }
|
||||
|
||||
void getMinRange ( float *axes ) const { memcpy ( axes, min , num_axes * sizeof(float) ) ; }
|
||||
void getMaxRange ( float *axes ) const { memcpy ( axes, max , num_axes * sizeof(float) ) ; }
|
||||
void getCenter ( float *axes ) const { memcpy ( axes, center, num_axes * sizeof(float) ) ; }
|
||||
|
||||
void read ( int *buttons, float *axes ) ;
|
||||
void rawRead ( int *buttons, float *axes ) ;
|
||||
// bool SetForceFeedBack ( int axe, float force );
|
||||
} ;
|
||||
|
||||
extern void jsInit () ;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
12
include/plib/net.h
Normal file
12
include/plib/net.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef __PLIB_NET_H__
|
||||
#define __PLIB_NET_H__ 1
|
||||
|
||||
#include <plib/netBuffer.h>
|
||||
#include <plib/netChannel.h>
|
||||
#include <plib/netChat.h>
|
||||
#include <plib/netMessage.h>
|
||||
#include <plib/netMonitor.h>
|
||||
#include <plib/netSocket.h>
|
||||
|
||||
#endif
|
||||
|
||||
234
include/plib/netBuffer.h
Normal file
234
include/plib/netBuffer.h
Normal file
@@ -0,0 +1,234 @@
|
||||
/*
|
||||
PLIB - A Suite of Portable Game Libraries
|
||||
Copyright (C) 1998,2002 Steve Baker
|
||||
|
||||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information visit http://plib.sourceforge.net
|
||||
|
||||
$Id: netBuffer.h 1901 2004-03-21 18:19:11Z sjbaker $
|
||||
*/
|
||||
|
||||
/****
|
||||
* NAME
|
||||
* netBuffer - network buffer class
|
||||
*
|
||||
* DESCRIPTION
|
||||
* Clients and servers built on top of netBufferChannel
|
||||
* automatically support pipelining.
|
||||
*
|
||||
* Pipelining refers to a protocol capability. Normally,
|
||||
* a conversation with a server has a back-and-forth
|
||||
* quality to it. The client sends a command, and
|
||||
* waits for the response. If a client needs to send
|
||||
* many commands over a high-latency connection,
|
||||
* waiting for each response can take a long time.
|
||||
*
|
||||
* For example, when sending a mail message to many recipients
|
||||
* with SMTP, the client will send a series of RCPT commands, one
|
||||
* for each recipient. For each of these commands, the server will
|
||||
* send back a reply indicating whether the mailbox specified is
|
||||
* valid. If you want to send a message to several hundred recipients,
|
||||
* this can be rather tedious if the round-trip time for each command
|
||||
* is long. You'd like to be able to send a bunch of RCPT commands
|
||||
* in one batch, and then count off the responses to them as they come.
|
||||
*
|
||||
* I have a favorite visual when explaining the advantages of
|
||||
* pipelining. Imagine each request to the server is a boxcar on a train.
|
||||
* The client is in Los Angeles, and the server is in New York.
|
||||
* Pipelining lets you hook all your cars in one long chain; send
|
||||
* them to New York, where they are filled and sent back to you.
|
||||
* Without pipelining you have to send one car at a time.
|
||||
*
|
||||
* Not all protocols allow pipelining. Not all servers support it;
|
||||
* Sendmail, for example, does not support pipelining because it tends
|
||||
* to fork unpredictably, leaving buffered data in a questionable state.
|
||||
* A recent extension to the SMTP protocol allows a server to specify
|
||||
* whether it supports pipelining. HTTP/1.1 explicitly requires that
|
||||
* a server support pipelining.
|
||||
*
|
||||
* NOTES
|
||||
* When a user passes in a buffer object, it belongs to
|
||||
* the user. When the library gives a buffer to the user,
|
||||
* the user should copy it.
|
||||
*
|
||||
* AUTHORS
|
||||
* Sam Rushing <rushing@nightmare.com> - original version for Medusa
|
||||
* Dave McClurg <dpm@efn.org> - modified for use in PLIB
|
||||
*
|
||||
* CREATION DATE
|
||||
* Dec-2000
|
||||
*
|
||||
****/
|
||||
|
||||
#ifndef NET_BUFFER_H
|
||||
#define NET_BUFFER_H
|
||||
|
||||
#include "netChannel.h"
|
||||
|
||||
|
||||
// ===========================================================================
|
||||
// netName
|
||||
// ===========================================================================
|
||||
|
||||
enum { NET_MAX_NAME = 31 } ;
|
||||
//eg. char name [ NET_MAX_NAME+1 ] ;
|
||||
|
||||
|
||||
inline char* netCopyName ( char* dst, const char* src )
|
||||
{
|
||||
if ( src != NULL )
|
||||
{
|
||||
strncpy ( dst, src, NET_MAX_NAME ) ;
|
||||
dst [ NET_MAX_NAME ] = 0 ;
|
||||
}
|
||||
else
|
||||
*dst = 0 ;
|
||||
return dst ;
|
||||
}
|
||||
|
||||
|
||||
// ===========================================================================
|
||||
// netBuffer
|
||||
// ===========================================================================
|
||||
|
||||
class netBuffer
|
||||
{
|
||||
protected:
|
||||
int length ;
|
||||
int max_length ;
|
||||
char* data ;
|
||||
|
||||
public:
|
||||
netBuffer ( int _max_length )
|
||||
{
|
||||
length = 0 ;
|
||||
max_length = _max_length ;
|
||||
data = new char [ max_length+1 ] ; //for null terminator
|
||||
}
|
||||
|
||||
~netBuffer ()
|
||||
{
|
||||
delete[] data ;
|
||||
}
|
||||
|
||||
int getLength() const { return length ; }
|
||||
int getMaxLength() const { return max_length ; }
|
||||
|
||||
/*
|
||||
** getData() returns a pointer to the data
|
||||
** Note: a zero (0) byte is appended for convenience
|
||||
** but the data may have internal zero (0) bytes already
|
||||
*/
|
||||
char* getData() { data [length] = 0 ; return data ; }
|
||||
const char* getData() const { ((char*)data) [length] = 0 ; return data ; }
|
||||
|
||||
void remove ()
|
||||
{
|
||||
length = 0 ;
|
||||
}
|
||||
|
||||
void remove (int pos, int n)
|
||||
{
|
||||
assert (pos>=0 && pos<length && (pos+n)<=length) ;
|
||||
//if (pos>=0 && pos<length && (pos+n)<=length)
|
||||
{
|
||||
memmove(&data[pos],&data[pos+n],length-(pos+n)) ;
|
||||
length -= n ;
|
||||
}
|
||||
}
|
||||
|
||||
bool append (const char* s, int n)
|
||||
{
|
||||
if ((length+n)<=max_length)
|
||||
{
|
||||
memcpy(&data[length],s,n) ;
|
||||
length += n ;
|
||||
return true ;
|
||||
}
|
||||
return false ;
|
||||
}
|
||||
|
||||
bool append (int n)
|
||||
{
|
||||
if ((length+n)<=max_length)
|
||||
{
|
||||
length += n ;
|
||||
return true ;
|
||||
}
|
||||
return false ;
|
||||
}
|
||||
} ;
|
||||
|
||||
// ===========================================================================
|
||||
// netBufferChannel
|
||||
// ===========================================================================
|
||||
|
||||
class netBufferChannel : public netChannel
|
||||
{
|
||||
netBuffer in_buffer;
|
||||
netBuffer out_buffer;
|
||||
int should_close ;
|
||||
|
||||
virtual bool readable (void)
|
||||
{
|
||||
return (netChannel::readable() &&
|
||||
(in_buffer.getLength() < in_buffer.getMaxLength()));
|
||||
}
|
||||
|
||||
virtual void handleRead (void) ;
|
||||
|
||||
virtual bool writable (void)
|
||||
{
|
||||
return (out_buffer.getLength() || should_close);
|
||||
}
|
||||
|
||||
virtual void handleWrite (void) ;
|
||||
|
||||
public:
|
||||
|
||||
netBufferChannel (int in_buffer_size = 4096, int out_buffer_size = 16384) :
|
||||
in_buffer (in_buffer_size),
|
||||
out_buffer (out_buffer_size),
|
||||
should_close (0)
|
||||
{ /* empty */
|
||||
}
|
||||
|
||||
virtual void handleClose ( void )
|
||||
{
|
||||
in_buffer.remove () ;
|
||||
out_buffer.remove () ;
|
||||
should_close = 0 ;
|
||||
netChannel::handleClose () ;
|
||||
}
|
||||
|
||||
void closeWhenDone (void) { should_close = 1 ; }
|
||||
|
||||
virtual bool bufferSend (const char* msg, int msg_len)
|
||||
{
|
||||
if ( out_buffer.append(msg,msg_len) )
|
||||
return true ;
|
||||
ulSetError ( UL_WARNING, "netBufferChannel: output buffer overflow!" ) ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
virtual void handleBufferRead (netBuffer& buffer)
|
||||
{
|
||||
/* do something here */
|
||||
buffer.remove();
|
||||
}
|
||||
};
|
||||
|
||||
#endif // NET_BUFFER_H
|
||||
116
include/plib/netChannel.h
Normal file
116
include/plib/netChannel.h
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
PLIB - A Suite of Portable Game Libraries
|
||||
Copyright (C) 1998,2002 Steve Baker
|
||||
|
||||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information visit http://plib.sourceforge.net
|
||||
|
||||
$Id: netChannel.h 1899 2004-03-21 17:41:07Z sjbaker $
|
||||
*/
|
||||
|
||||
/****
|
||||
* NAME
|
||||
* netChannel - network channel class
|
||||
*
|
||||
* DESCRIPTION
|
||||
* netChannel is adds event-handling to the low-level
|
||||
* netSocket class. Otherwise, it can be treated as
|
||||
* a normal non-blocking socket object.
|
||||
*
|
||||
* The direct interface between the netPoll() loop and
|
||||
* the channel object are the handleReadEvent and
|
||||
* handleWriteEvent methods. These are called
|
||||
* whenever a channel object 'fires' that event.
|
||||
*
|
||||
* The firing of these low-level events can tell us whether
|
||||
* certain higher-level events have taken place, depending on
|
||||
* the timing and state of the connection.
|
||||
*
|
||||
* AUTHORS
|
||||
* Sam Rushing <rushing@nightmare.com> - original version for Medusa
|
||||
* Dave McClurg <dpm@efn.org> - modified for use in PLIB
|
||||
*
|
||||
* CREATION DATE
|
||||
* Dec-2000
|
||||
*
|
||||
****/
|
||||
|
||||
#ifndef NET_CHANNEL_H
|
||||
#define NET_CHANNEL_H
|
||||
|
||||
#include "netSocket.h"
|
||||
|
||||
class netChannel : public netSocket
|
||||
{
|
||||
bool closed, connected, accepting, write_blocked, should_delete ;
|
||||
netChannel* next_channel ;
|
||||
|
||||
friend bool netPoll (unsigned int timeout);
|
||||
|
||||
public:
|
||||
|
||||
netChannel () ;
|
||||
virtual ~netChannel () ;
|
||||
|
||||
void setHandle (int s, bool is_connected = true);
|
||||
bool isConnected () const { return connected; }
|
||||
bool isClosed () const { return closed; }
|
||||
void shouldDelete () { should_delete = true ; }
|
||||
|
||||
// --------------------------------------------------
|
||||
// socket methods
|
||||
// --------------------------------------------------
|
||||
|
||||
bool open ( void ) ;
|
||||
void close ( void ) ;
|
||||
int listen ( int backlog ) ;
|
||||
int connect ( const char* host, int port ) ;
|
||||
int send ( const void * buf, int size, int flags = 0 ) ;
|
||||
int recv ( void * buf, int size, int flags = 0 ) ;
|
||||
|
||||
// poll() eligibility predicates
|
||||
virtual bool readable (void) { return (connected || accepting); }
|
||||
virtual bool writable (void) { return (!connected || write_blocked); }
|
||||
|
||||
// --------------------------------------------------
|
||||
// event handlers
|
||||
// --------------------------------------------------
|
||||
|
||||
void handleReadEvent (void);
|
||||
void handleWriteEvent (void);
|
||||
|
||||
// These are meant to be overridden.
|
||||
virtual void handleClose (void) {
|
||||
//ulSetError(UL_WARNING,"Network: %d: unhandled close",getHandle());
|
||||
}
|
||||
virtual void handleRead (void) {
|
||||
ulSetError(UL_WARNING,"Network: %d: unhandled read",getHandle());
|
||||
}
|
||||
virtual void handleWrite (void) {
|
||||
ulSetError(UL_WARNING,"Network: %d: unhandled write",getHandle());
|
||||
}
|
||||
virtual void handleAccept (void) {
|
||||
ulSetError(UL_WARNING,"Network: %d: unhandled accept",getHandle());
|
||||
}
|
||||
virtual void handleError (int error) {
|
||||
ulSetError(UL_WARNING,"Network: %d: errno: %s(%d)",getHandle(),strerror(errno),errno);
|
||||
}
|
||||
|
||||
static bool poll (unsigned int timeout = 0 ) ;
|
||||
static void loop (unsigned int timeout = 0 ) ;
|
||||
};
|
||||
|
||||
#endif // NET_CHANNEL_H
|
||||
86
include/plib/netChat.h
Normal file
86
include/plib/netChat.h
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
PLIB - A Suite of Portable Game Libraries
|
||||
Copyright (C) 1998,2002 Steve Baker
|
||||
|
||||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information visit http://plib.sourceforge.net
|
||||
|
||||
$Id: netChat.h 1568 2002-09-02 06:05:49Z sjbaker $
|
||||
*/
|
||||
|
||||
/****
|
||||
* NAME
|
||||
* netChat - network chat class
|
||||
*
|
||||
* DESCRIPTION
|
||||
* This class adds support for 'chat' style protocols -
|
||||
* where one side sends a 'command', and the other sends
|
||||
* a response (examples would be the common internet
|
||||
* protocols - smtp, nntp, ftp, etc..).
|
||||
*
|
||||
* The handle_buffer_read() method looks at the input
|
||||
* stream for the current 'terminator' (usually '\r\n'
|
||||
* for single-line responses, '\r\n.\r\n' for multi-line
|
||||
* output), calling found_terminator() on its receipt.
|
||||
*
|
||||
* EXAMPLE
|
||||
* Say you build an nntp client using this class.
|
||||
* At the start of the connection, you'll have
|
||||
* terminator set to '\r\n', in order to process
|
||||
* the single-line greeting. Just before issuing a
|
||||
* 'LIST' command you'll set it to '\r\n.\r\n'.
|
||||
* The output of the LIST command will be accumulated
|
||||
* (using your own 'collect_incoming_data' method)
|
||||
* up to the terminator, and then control will be
|
||||
* returned to you - by calling your found_terminator()
|
||||
*
|
||||
* AUTHORS
|
||||
* Sam Rushing <rushing@nightmare.com> - original version for Medusa
|
||||
* Dave McClurg <dpm@efn.org> - modified for use in PLIB
|
||||
*
|
||||
* CREATION DATE
|
||||
* Dec-2000
|
||||
*
|
||||
****/
|
||||
|
||||
#ifndef NET_CHAT_H
|
||||
#define NET_CHAT_H
|
||||
|
||||
#include "netBuffer.h"
|
||||
|
||||
class netChat : public netBufferChannel
|
||||
{
|
||||
char* terminator;
|
||||
|
||||
virtual void handleBufferRead (netBuffer& buffer) ;
|
||||
|
||||
public:
|
||||
|
||||
netChat () : terminator (0) {}
|
||||
|
||||
void setTerminator (const char* t);
|
||||
const char* getTerminator (void);
|
||||
|
||||
bool push (const char* s)
|
||||
{
|
||||
return bufferSend ( s, strlen(s) ) ;
|
||||
}
|
||||
|
||||
virtual void collectIncomingData (const char* s, int n) {}
|
||||
virtual void foundTerminator (void) {}
|
||||
};
|
||||
|
||||
#endif // NET_CHAT_H
|
||||
294
include/plib/netMessage.h
Normal file
294
include/plib/netMessage.h
Normal file
@@ -0,0 +1,294 @@
|
||||
/*
|
||||
PLIB - A Suite of Portable Game Libraries
|
||||
Copyright (C) 1998,2002 Steve Baker
|
||||
|
||||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information visit http://plib.sourceforge.net
|
||||
|
||||
$Id: netMessage.h 2112 2006-12-12 18:45:28Z fayjf $
|
||||
*/
|
||||
|
||||
/****
|
||||
* NAME
|
||||
* netMessage - message buffer and channel classes
|
||||
*
|
||||
* DESCRIPTION
|
||||
* messages are a binary format for sending buffers over a channel.
|
||||
* message headers contain a type field and length.
|
||||
*
|
||||
* AUTHOR
|
||||
* Dave McClurg <dpm@efn.org>
|
||||
*
|
||||
* CREATION DATE
|
||||
* Dec-2000
|
||||
****/
|
||||
|
||||
#ifndef __NET_MESSAGE__
|
||||
#define __NET_MESSAGE__
|
||||
|
||||
|
||||
#include "netBuffer.h"
|
||||
|
||||
// ntohs() etc prototypes
|
||||
#ifdef UL_MSVC
|
||||
#include <winsock2.h>
|
||||
#else
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
|
||||
class netGuid //Globally Unique IDentifier
|
||||
{
|
||||
public:
|
||||
unsigned char data [ 16 ] ;
|
||||
|
||||
netGuid () {}
|
||||
|
||||
netGuid ( unsigned int l,
|
||||
unsigned short w1, unsigned short w2,
|
||||
unsigned char b1, unsigned char b2,
|
||||
unsigned char b3, unsigned char b4,
|
||||
unsigned char b5, unsigned char b6,
|
||||
unsigned char b7, unsigned char b8 )
|
||||
{
|
||||
//store in network format (big-endian)
|
||||
|
||||
data[ 0] = (unsigned char)(l>>24) ;
|
||||
data[ 1] = (unsigned char)(l>>16) ;
|
||||
data[ 2] = (unsigned char)(l>> 8) ;
|
||||
data[ 3] = (unsigned char)(l ) ;
|
||||
data[ 4] = (unsigned char)(w1>>8) ;
|
||||
data[ 5] = (unsigned char)(w1 ) ;
|
||||
data[ 6] = (unsigned char)(w2>>8) ;
|
||||
data[ 7] = (unsigned char)(w2 ) ;
|
||||
|
||||
data[ 8] = b1 ;
|
||||
data[ 9] = b2 ;
|
||||
data[10] = b3 ;
|
||||
data[11] = b4 ;
|
||||
data[12] = b5 ;
|
||||
data[13] = b6 ;
|
||||
data[14] = b7 ;
|
||||
data[15] = b8 ;
|
||||
}
|
||||
|
||||
bool operator ==( const netGuid& guid ) const
|
||||
{
|
||||
return memcmp ( data, guid.data, sizeof(data) ) == 0 ;
|
||||
}
|
||||
|
||||
bool operator !=( const netGuid& guid ) const
|
||||
{
|
||||
return memcmp ( data, guid.data, sizeof(data) ) != 0 ;
|
||||
}
|
||||
} ;
|
||||
|
||||
|
||||
class netMessage : public netBuffer
|
||||
{
|
||||
int pos ;
|
||||
|
||||
void seek ( int new_pos ) const
|
||||
{
|
||||
if ( new_pos < 0 )
|
||||
new_pos = 0 ;
|
||||
else
|
||||
if ( new_pos > length )
|
||||
new_pos = length ;
|
||||
|
||||
//logical const-ness
|
||||
|
||||
((netMessage*)this) -> pos = new_pos ;
|
||||
}
|
||||
|
||||
void skip ( int off ) const
|
||||
{
|
||||
seek(pos+off);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
// incoming message; header is already there
|
||||
netMessage ( const char* s, int n ) : netBuffer(n)
|
||||
{
|
||||
assert ( n >= 5 ) ;
|
||||
append(s,n);
|
||||
pos = 5 ; // seek past header
|
||||
}
|
||||
|
||||
// outgoing message
|
||||
netMessage ( int type, int to_id, int from_id=0, int n=256 ) : netBuffer(n)
|
||||
{
|
||||
// output header
|
||||
putw ( 0 ) ; //msg_len
|
||||
putbyte ( type ) ;
|
||||
putbyte ( to_id ) ;
|
||||
putbyte ( from_id ) ;
|
||||
}
|
||||
|
||||
int getType () const { return ( (unsigned char*)data )[ 2 ] ; }
|
||||
int getToID () const { return ( (unsigned char*)data )[ 3 ] ; }
|
||||
int getFromID () const { return ( (unsigned char*)data )[ 4 ] ; }
|
||||
void setFromID ( int from_id ) { ( (unsigned char*)data )[ 4 ] = (unsigned char)from_id; }
|
||||
|
||||
void geta ( void* a, int n ) const
|
||||
{
|
||||
assert (pos>=0 && pos<length && (pos+n)<=length) ;
|
||||
//if (pos>=0 && pos<length && (pos+n)<=length)
|
||||
{
|
||||
memcpy(a,&data[pos],n) ;
|
||||
seek(pos+n);
|
||||
}
|
||||
}
|
||||
void puta ( const void* a, int n )
|
||||
{
|
||||
append((const char*)a,n);
|
||||
pos = length;
|
||||
*((unsigned short*)data) = (unsigned short)length ; //update msg_len
|
||||
}
|
||||
|
||||
int getbyte () const
|
||||
{
|
||||
unsigned char temp ;
|
||||
geta(&temp,sizeof(temp)) ;
|
||||
return temp ;
|
||||
}
|
||||
void putbyte ( int c )
|
||||
{
|
||||
unsigned char temp = c ;
|
||||
puta(&temp,sizeof(temp)) ;
|
||||
}
|
||||
|
||||
bool getb () const
|
||||
{
|
||||
unsigned char temp ;
|
||||
geta(&temp,sizeof(temp)) ;
|
||||
return temp != 0 ;
|
||||
}
|
||||
void putb ( bool b )
|
||||
{
|
||||
unsigned char temp = b? 1: 0 ;
|
||||
puta(&temp,sizeof(temp)) ;
|
||||
}
|
||||
|
||||
int getw () const
|
||||
{
|
||||
unsigned short temp ;
|
||||
geta ( &temp, sizeof(temp) ) ;
|
||||
return int ( ntohs ( temp ) ) ;
|
||||
}
|
||||
void putw ( int i )
|
||||
{
|
||||
unsigned short temp = htons ( (unsigned short) i ) ;
|
||||
puta ( &temp, sizeof(temp) ) ;
|
||||
}
|
||||
|
||||
int geti () const
|
||||
{
|
||||
unsigned int temp ;
|
||||
geta ( &temp, sizeof(temp) ) ;
|
||||
return int ( ntohl ( temp ) ) ;
|
||||
}
|
||||
void puti ( int i )
|
||||
{
|
||||
unsigned int temp = htonl ( (unsigned int) i ) ;
|
||||
puta ( &temp, sizeof(temp) ) ;
|
||||
}
|
||||
|
||||
void getfv ( float* fv, int n ) const
|
||||
{
|
||||
unsigned int* v = (unsigned int*)fv;
|
||||
geta ( v, (n<<2) ) ;
|
||||
for ( int i=0; i<n; i++ )
|
||||
v[i] = ntohl ( v[i] ) ;
|
||||
}
|
||||
void putfv ( const float* fv, int n )
|
||||
{
|
||||
const unsigned int* v = (const unsigned int*)fv;
|
||||
for ( int i=0; i<n; i++ )
|
||||
{
|
||||
unsigned int temp = htonl ( v[i] ) ;
|
||||
puta ( &temp, sizeof(temp) ) ;
|
||||
}
|
||||
}
|
||||
|
||||
float getf () const
|
||||
{
|
||||
unsigned int temp ;
|
||||
geta ( &temp, sizeof(temp) ) ;
|
||||
temp = ntohl ( temp ) ;
|
||||
return *((float*)&temp) ;
|
||||
}
|
||||
void putf ( float f )
|
||||
{
|
||||
unsigned int temp = *((unsigned int*)&f) ;
|
||||
temp = htonl ( temp ) ;
|
||||
puta ( &temp, sizeof(temp) ) ;
|
||||
}
|
||||
|
||||
void gets ( char* s, int n ) const
|
||||
{
|
||||
char* src = &data[pos];
|
||||
char* dst = s;
|
||||
while (pos<length)
|
||||
{
|
||||
char ch = *src++;
|
||||
if ((dst-s)<(n-1))
|
||||
*dst++ = ch ;
|
||||
((netMessage*)this)->pos++;
|
||||
if (ch==0)
|
||||
break;
|
||||
}
|
||||
*dst = 0 ;
|
||||
}
|
||||
void puts ( const char* s )
|
||||
{
|
||||
puta(s,strlen(s)+1);
|
||||
}
|
||||
|
||||
void print ( FILE *fd = stderr ) const
|
||||
{
|
||||
fprintf ( fd, "netMessage: %p, length=%d\n", this, length ) ;
|
||||
fprintf ( fd, " header (type,to,from) = (%d,%d,%d)\n",
|
||||
getType(), getToID(), getFromID() ) ;
|
||||
fprintf ( fd, " data = " ) ;
|
||||
for ( int i=0; i<length; i++ )
|
||||
fprintf ( fd, "%02x ", data[i] ) ;
|
||||
fprintf ( fd, "\n" ) ;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class netMessageChannel : public netBufferChannel
|
||||
{
|
||||
virtual void handleBufferRead (netBuffer& buffer) ;
|
||||
|
||||
public:
|
||||
|
||||
bool sendMessage ( const netMessage& msg )
|
||||
{
|
||||
return bufferSend ( msg.getData(), msg.getLength() ) ;
|
||||
}
|
||||
|
||||
virtual void handleMessage ( const netMessage& msg ) {}
|
||||
};
|
||||
|
||||
|
||||
#endif //__NET_MESSAGE__
|
||||
106
include/plib/netMonitor.h
Normal file
106
include/plib/netMonitor.h
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
PLIB - A Suite of Portable Game Libraries
|
||||
Copyright (C) 1998,2002 Steve Baker
|
||||
|
||||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information visit http://plib.sourceforge.net
|
||||
|
||||
$Id: netMonitor.h 1899 2004-03-21 17:41:07Z sjbaker $
|
||||
*/
|
||||
|
||||
/****
|
||||
* NAME
|
||||
* netMonitor - network monitor server
|
||||
*
|
||||
* DESCRIPTION
|
||||
* netMonitor is a telnet command port with
|
||||
* password authorization. It can be paired
|
||||
* with and used to remotely admin another server.
|
||||
*
|
||||
* AUTHORS
|
||||
* Sam Rushing <rushing@nightmare.com> - original version for Medusa
|
||||
* Dave McClurg <dpm@efn.org> - modified for use in PLIB
|
||||
*
|
||||
* CREATION DATE
|
||||
* Dec-2000
|
||||
*
|
||||
****/
|
||||
|
||||
#ifndef NET_MONITOR_H
|
||||
#define NET_MONITOR_H
|
||||
|
||||
#include "netChat.h"
|
||||
|
||||
|
||||
class netMonitorServer : private netChannel
|
||||
{
|
||||
char* name ;
|
||||
char* password ;
|
||||
char* prompt ;
|
||||
void (*cmdfunc)(const char*) ;
|
||||
class netMonitorChannel* active ;
|
||||
|
||||
friend class netMonitorChannel ;
|
||||
|
||||
virtual bool writable (void) { return false ; }
|
||||
virtual void handleAccept (void) ;
|
||||
|
||||
public:
|
||||
|
||||
netMonitorServer( const char* _name, int port )
|
||||
{
|
||||
name = ulStrDup(_name);
|
||||
password = ulStrDup("") ;
|
||||
prompt = ulStrDup(">>> ");
|
||||
cmdfunc = 0 ;
|
||||
active = 0 ;
|
||||
|
||||
open () ;
|
||||
bind ("", port);
|
||||
listen (1);
|
||||
|
||||
ulSetError(UL_DEBUG, "Monitor \"%s\" started on port %d",name,port);
|
||||
}
|
||||
|
||||
~netMonitorServer()
|
||||
{
|
||||
delete[] name ;
|
||||
delete[] password ;
|
||||
delete[] prompt ;
|
||||
}
|
||||
|
||||
const char* getPassword () const { return password; }
|
||||
void setPassword ( const char* string )
|
||||
{
|
||||
delete[] password ;
|
||||
password = ulStrDup ( string?string:"" ) ;
|
||||
}
|
||||
|
||||
void setPrompt ( const char* string )
|
||||
{
|
||||
delete[] prompt ;
|
||||
prompt = ulStrDup ( string?string:"" ) ;
|
||||
}
|
||||
|
||||
void setCommandFunc ( void (*func)(const char*) )
|
||||
{
|
||||
cmdfunc = func ;
|
||||
}
|
||||
|
||||
bool push (const char* s) ;
|
||||
} ;
|
||||
|
||||
#endif // NET_MONITOR_H
|
||||
128
include/plib/netSocket.h
Normal file
128
include/plib/netSocket.h
Normal file
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
PLIB - A Suite of Portable Game Libraries
|
||||
Copyright (C) 1998,2002 Steve Baker
|
||||
|
||||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information visit http://plib.sourceforge.net
|
||||
|
||||
$Id: netSocket.h 2135 2008-11-10 15:40:28Z fayjf $
|
||||
*/
|
||||
|
||||
/****
|
||||
* NAME
|
||||
* netSocket - network sockets
|
||||
*
|
||||
* DESCRIPTION
|
||||
* netSocket is a thin C++ wrapper over bsd sockets to
|
||||
* facilitate porting to other platforms
|
||||
*
|
||||
* AUTHOR
|
||||
* Dave McClurg <dpm@efn.org>
|
||||
*
|
||||
* CREATION DATE
|
||||
* Dec-2000
|
||||
*
|
||||
****/
|
||||
|
||||
#ifndef NET_SOCKET_H
|
||||
#define NET_SOCKET_H
|
||||
|
||||
#include "ul.h"
|
||||
#include <errno.h>
|
||||
|
||||
#if defined(UL_MAC_OSX)
|
||||
# include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Socket address, internet style.
|
||||
*/
|
||||
class netAddress
|
||||
{
|
||||
/* DANGER!!! This MUST match 'struct sockaddr_in' exactly! */
|
||||
#ifdef UL_MAC_OSX
|
||||
// This member is added since OS X 10.5.2 ... I'm wondering how to handle this...
|
||||
__uint8_t sin_len;
|
||||
__uint8_t sin_family;
|
||||
in_port_t sin_port;
|
||||
in_addr_t sin_addr;
|
||||
char sin_zero[8];
|
||||
#else
|
||||
short sin_family ;
|
||||
unsigned short sin_port ;
|
||||
unsigned int sin_addr ;
|
||||
char sin_zero [ 8 ] ;
|
||||
#endif
|
||||
|
||||
public:
|
||||
netAddress () {}
|
||||
netAddress ( const char* host, int port ) ;
|
||||
|
||||
void set ( const char* host, int port ) ;
|
||||
const char* getHost () const ;
|
||||
unsigned int getPort() const ;
|
||||
unsigned int getIP () const ;
|
||||
unsigned int getFamily () const ;
|
||||
static const char* getLocalHost () ;
|
||||
|
||||
bool getBroadcast () const ;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Socket type
|
||||
*/
|
||||
class netSocket
|
||||
{
|
||||
int handle ;
|
||||
|
||||
public:
|
||||
|
||||
netSocket () ;
|
||||
virtual ~netSocket () ;
|
||||
|
||||
int getHandle () const { return handle; }
|
||||
void setHandle (int handle) ;
|
||||
|
||||
bool open ( bool stream=true ) ;
|
||||
void close ( void ) ;
|
||||
int bind ( const char* host, int port ) ;
|
||||
int listen ( int backlog ) ;
|
||||
int accept ( netAddress* addr ) ;
|
||||
int connect ( const char* host, int port ) ;
|
||||
int send ( const void * buffer, int size, int flags = 0 ) ;
|
||||
int sendto ( const void * buffer, int size, int flags, const netAddress* to ) ;
|
||||
int recv ( void * buffer, int size, int flags = 0 ) ;
|
||||
int recvfrom ( void * buffer, int size, int flags, netAddress* from ) ;
|
||||
|
||||
void setBlocking ( bool blocking ) ;
|
||||
void setBroadcast ( bool broadcast ) ;
|
||||
|
||||
static bool isNonBlockingError () ;
|
||||
static int select ( netSocket** reads, netSocket** writes, int timeout ) ;
|
||||
} ;
|
||||
|
||||
|
||||
int netInit ( int* argc, char** argv = NULL ) ; /* Legacy */
|
||||
|
||||
int netInit () ;
|
||||
|
||||
|
||||
const char* netFormat ( const char* fmt, ... ) ;
|
||||
|
||||
|
||||
#endif // NET_SOCKET_H
|
||||
|
||||
1615
include/plib/pu.h
Normal file
1615
include/plib/pu.h
Normal file
File diff suppressed because it is too large
Load Diff
944
include/plib/puAux.h
Normal file
944
include/plib/puAux.h
Normal file
@@ -0,0 +1,944 @@
|
||||
/*
|
||||
PUI Auxiliary Widget Library
|
||||
Derived from PLIB, the Portable Game Library by Steve Baker.
|
||||
|
||||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information visit http://plib.sourceforge.net
|
||||
|
||||
$Id: puAux.h 2160 2010-02-27 03:48:23Z fayjf $
|
||||
*/
|
||||
|
||||
#ifndef _PUI_AUX_WIDGETS_H_
|
||||
#define _PUI_AUX_WIDGETS_H_ 1
|
||||
|
||||
#include "pu.h"
|
||||
|
||||
// Widget Class Bit Patterns
|
||||
// PUI classes take up 0x00000001 through 0x00020000
|
||||
|
||||
#define PUCLASS_FILESELECTOR 0x00040000 /* Because FilePicker is obsolete */
|
||||
#define PUCLASS_BISLIDER 0x00080000
|
||||
#define PUCLASS_TRISLIDER 0x00100000
|
||||
#define PUCLASS_VERTMENU 0x00200000
|
||||
#define PUCLASS_LARGEINPUT 0x00400000
|
||||
#define PUCLASS_COMBOBOX 0x00800000
|
||||
#define PUCLASS_SELECTBOX 0x01000000
|
||||
#define PUCLASS_SPINBOX 0x02000000
|
||||
#define PUCLASS_SCROLLBAR 0x04000000
|
||||
#define PUCLASS_BISLIDERWITHENDS 0x08000000
|
||||
#define PUCLASS_SLIDERWITHINPUT 0x10000000
|
||||
#define PUCLASS_COMPASS 0x20000000
|
||||
#define PUCLASS_CHOOSER 0x40000000
|
||||
#define PUCLASS_LIST 0x80000000
|
||||
|
||||
|
||||
// Widget Declarations
|
||||
class puaSpinBox ;
|
||||
class puaFileSelector ;
|
||||
class puaBiSlider ;
|
||||
class puaTriSlider ;
|
||||
class puaVerticalMenu ;
|
||||
class puaLargeInput ;
|
||||
class puaComboBox ;
|
||||
class puaSelectBox ;
|
||||
class puaScrollBar ;
|
||||
class puaBiSliderWithEnds ;
|
||||
class puaCompass ;
|
||||
class puaSliderWithInput ;
|
||||
class puaChooser ;
|
||||
class puaList ;
|
||||
|
||||
|
||||
// A File selector widget
|
||||
class puaFileSelector : public puDialogBox
|
||||
{
|
||||
UL_TYPE_DATA
|
||||
|
||||
protected:
|
||||
char** files ;
|
||||
char* dflag ;
|
||||
int num_files ;
|
||||
int arrow_count ;
|
||||
|
||||
char *startDir ;
|
||||
|
||||
void find_files ( void ) ;
|
||||
static void handle_select ( puObject* ) ;
|
||||
static void input_entered ( puObject* ) ;
|
||||
|
||||
puFrame *frame ;
|
||||
puListBox *list_box ;
|
||||
puSlider *slider ;
|
||||
puOneShot *cancel_button ;
|
||||
puOneShot *ok_button ;
|
||||
puInput *input ;
|
||||
puArrowButton *up_arrow ;
|
||||
puArrowButton *down_arrow ;
|
||||
puArrowButton *fastup_arrow ;
|
||||
puArrowButton *fastdown_arrow ;
|
||||
|
||||
void puaFileSelectorInit ( int x, int y, int w, int h,
|
||||
int arrows, const char *dir, const char *title ) ;
|
||||
|
||||
public:
|
||||
|
||||
puaFileSelector ( int x, int y, int w, int h, int arrows,
|
||||
const char *dir, const char *title = "Pick a file" ) :
|
||||
puDialogBox ( x, y )
|
||||
{
|
||||
puaFileSelectorInit ( x, y, w, h, arrows, dir, title ) ;
|
||||
}
|
||||
|
||||
puaFileSelector ( int x, int y, int w, int h,
|
||||
const char *dir, const char *title = "Pick a file" ) :
|
||||
puDialogBox ( x, y )
|
||||
{
|
||||
puaFileSelectorInit ( x, y, w, h, 1, dir, title ) ;
|
||||
}
|
||||
|
||||
puaFileSelector ( int x, int y, int arrows,
|
||||
const char *dir, const char *title = "Pick a file" ) :
|
||||
puDialogBox ( x, y )
|
||||
{
|
||||
puaFileSelectorInit ( x, y, 220, 170, arrows, dir, title ) ;
|
||||
}
|
||||
|
||||
puaFileSelector ( int x, int y,
|
||||
const char *dir, const char *title = "Pick a file" ) :
|
||||
puDialogBox ( x, y )
|
||||
{
|
||||
puaFileSelectorInit ( x, y, 220, 170, 1, dir, title ) ;
|
||||
}
|
||||
|
||||
~puaFileSelector () ;
|
||||
|
||||
/* Not for application use!! */
|
||||
puInput *__getInput ( void ) const { return input ; }
|
||||
char *__getStartDir ( void ) const { return (char *) startDir ; }
|
||||
|
||||
void setInitialValue ( const char *fname ) ;
|
||||
void setSize ( int w, int h ) ;
|
||||
} ;
|
||||
|
||||
|
||||
// An input box that takes an arbitrary number of lines of input
|
||||
class puaLargeInput : public puInputBase, public puGroup
|
||||
{
|
||||
UL_TYPE_DATA
|
||||
|
||||
protected:
|
||||
int num_lines ; // Number of lines of text in the box
|
||||
int lines_in_window ; // Number of lines showing in the window
|
||||
int top_line_in_window ; // Number of the first line in the window
|
||||
int max_width ; // Width of longest line of text in box, in pixels
|
||||
int slider_width ;
|
||||
int line_height ; // Text height + interline gap
|
||||
int vgap ; // Gap on top and bottom
|
||||
int hgap ; // Gap on the left and right side
|
||||
int input_width ; // Width of display area (widget minus gaps & slider)
|
||||
int input_height ; // Height of display area
|
||||
|
||||
puFrame *frame ;
|
||||
puFrame *plug ; // Little square in the bottom right corner
|
||||
|
||||
puaScrollBar *bottom_slider ; // Horizontal slider at bottom of window
|
||||
puaScrollBar *right_slider ; // Vertical slider at right of window
|
||||
|
||||
int arrow_count ; // Number of up/down arrows above and below the right slider
|
||||
|
||||
void normalizeCursors ( void ) ;
|
||||
void removeSelectRegion ( void ) ;
|
||||
void updateGeometry ( void ) ;
|
||||
|
||||
char *wrapText ( int target_width = 0, int *numlines = 0, int *maxwidth = 0 ) ;
|
||||
void getTextProperties(int *numlines, int *maxwidth) ;
|
||||
char *getText () { return bottom_slider ? getStringValue () : getDisplayedText () ; }
|
||||
|
||||
public:
|
||||
puaLargeInput ( int x, int y, int w, int h, int arrows, int sl_width, int wrap_text = FALSE ) ;
|
||||
~puaLargeInput ()
|
||||
{
|
||||
if ( puActiveWidget() == this )
|
||||
puDeactivateWidget () ;
|
||||
}
|
||||
|
||||
void setSize ( int w, int h ) ;
|
||||
void setLegendFont ( puFont f ) { puGroup::setLegendFont ( f ) ; updateGeometry () ; }
|
||||
|
||||
int getNumLines ( void ) const { return num_lines ; }
|
||||
int getLinesInWindow ( void ) const { return lines_in_window ; }
|
||||
void setTopLineInWindow ( int val ) { top_line_in_window = (val<0) ? 0 : ( (val>num_lines-2) ? num_lines-2 : val ) ; }
|
||||
void setSliderPosition ( float fraction ) ;
|
||||
|
||||
void draw ( int dx, int dy ) ;
|
||||
int checkHit ( int button, int updown, int x, int y ) ;
|
||||
void doHit ( int button, int updown, int x, int y ) ;
|
||||
int checkKey ( int key, int updown ) ;
|
||||
|
||||
void setSelectRegion ( int s, int e ) ;
|
||||
void selectEntireLine ( void ) ;
|
||||
|
||||
void invokeDownCallback ( void )
|
||||
{
|
||||
rejectInput () ;
|
||||
normalizeCursors () ;
|
||||
if ( down_cb != NULL ) (*down_cb)(this) ;
|
||||
}
|
||||
|
||||
void setValue ( const char *s ) ;
|
||||
void addNewLine ( const char *l ) ;
|
||||
void addText ( const char *l ) ;
|
||||
void appendText ( const char *l ) ;
|
||||
void removeText ( int start, int end ) ;
|
||||
char *getDisplayedText ( void )
|
||||
{
|
||||
return ( displayed_text == NULL ? getStringValue () : displayed_text ) ;
|
||||
}
|
||||
} ;
|
||||
|
||||
|
||||
// A box that contains a set of alternatives that drop down when the user clicks on the down-arrow
|
||||
// Defined constants telling how the callback got triggered. This is needed for
|
||||
// cases in which the user has deleted the entry in the input box and wants that
|
||||
// entry deleted from the list of items.
|
||||
#define PUACOMBOBOX_CALLBACK_NONE 0
|
||||
#define PUACOMBOBOX_CALLBACK_INPUT 1
|
||||
#define PUACOMBOBOX_CALLBACK_ARROW 2
|
||||
class puaComboBox : public puGroup
|
||||
{
|
||||
UL_TYPE_DATA
|
||||
|
||||
protected:
|
||||
char ** list ;
|
||||
int num_items ;
|
||||
|
||||
int curr_item ;
|
||||
|
||||
puInput *input ;
|
||||
puArrowButton *arrow_btn ;
|
||||
puPopupMenu *popup_menu ;
|
||||
|
||||
int callback_source ;
|
||||
|
||||
static void input_cb ( puObject *inp ) ;
|
||||
static void input_active_cb ( puObject *inp ) ;
|
||||
static void input_down_cb ( puObject *inp ) ;
|
||||
static void handle_arrow ( puObject *arrow ) ;
|
||||
static void handle_popup ( puObject *popupm ) ;
|
||||
|
||||
void update_widgets ( void ) ;
|
||||
void update_current_item ( void ) ;
|
||||
void setCallbackSource ( int s ) { callback_source = s ; }
|
||||
|
||||
public:
|
||||
/* Not for application use ! */
|
||||
puPopupMenu * __getPopupMenu ( void ) const { return popup_menu ; }
|
||||
|
||||
void newList ( char ** _list ) ;
|
||||
int getNumItems ( void ) const { return num_items ; }
|
||||
char *getNewEntry ( void ) const { return input->getStringValue () ; }
|
||||
|
||||
int getCurrentItem ( void ) ;
|
||||
void setCurrentItem ( int item )
|
||||
{
|
||||
if ( ( item >= 0 ) && ( item < num_items ) )
|
||||
{
|
||||
curr_item = item ;
|
||||
update_widgets () ;
|
||||
|
||||
callback_source = PUACOMBOBOX_CALLBACK_ARROW ;
|
||||
invokeCallback () ;
|
||||
}
|
||||
}
|
||||
|
||||
void setCurrentItem ( const char *item_ptr ) ;
|
||||
|
||||
void setPosition ( int x, int y )
|
||||
{
|
||||
puGroup::setPosition ( x, y ) ;
|
||||
|
||||
/* Ensure that popup menu will show up at the right place */
|
||||
newList ( list ) ;
|
||||
}
|
||||
|
||||
void setSize ( int w, int h ) ;
|
||||
|
||||
void setValue ( float f ) { puValue::setValue ( f ) ; input->setValue ( f ) ; }
|
||||
void setValue ( int i ) { puValue::setValue ( i ) ; input->setValue ( i ) ; }
|
||||
void setValue ( const char *s ) { puValue::setValue ( s ) ; input->setValue ( s ) ; }
|
||||
void setValue ( puValue *pv ) { puValue::setValue ( pv ) ; input->setValue ( pv ) ; }
|
||||
|
||||
void draw ( int dx, int dy ) ;
|
||||
int checkHit ( int button, int updown, int x, int y ) ;
|
||||
int checkKey ( int key, int updown ) ;
|
||||
|
||||
int getCallbackSource ( void ) const { return callback_source ; }
|
||||
|
||||
virtual void setColourScheme ( float r, float g, float b, float a = 1.0f ) ;
|
||||
virtual void setColour ( int which, float r, float g, float b, float a = 1.0f ) ;
|
||||
|
||||
puaComboBox ( int minx, int miny, int maxx, int maxy,
|
||||
char **list, int editable = TRUE ) ;
|
||||
|
||||
~puaComboBox ()
|
||||
{
|
||||
int i ;
|
||||
for ( i = 0; i < num_items; i++ )
|
||||
delete [] list[i] ;
|
||||
|
||||
delete [] list ;
|
||||
}
|
||||
} ;
|
||||
|
||||
|
||||
// Like a menu bar, but the selections are one above the other
|
||||
class puaVerticalMenu : public puGroup
|
||||
{
|
||||
UL_TYPE_DATA
|
||||
|
||||
protected:
|
||||
public:
|
||||
puaVerticalMenu ( int x = -1, int y = -1 ) :
|
||||
|
||||
puGroup ( x < 0 ? puGetWindowWidth() -
|
||||
( puGetDefaultLegendFont().getStringWidth ( " " )
|
||||
+ PUSTR_TGAP + PUSTR_BGAP ) : x,
|
||||
|
||||
y < 0 ? puGetWindowHeight() -
|
||||
( puGetDefaultLegendFont().getStringHeight ()
|
||||
+ PUSTR_TGAP + PUSTR_BGAP ) : y)
|
||||
{
|
||||
type |= PUCLASS_VERTMENU ;
|
||||
floating = TRUE ; // DEPRECATED! -- we need to replace this code.
|
||||
if ( y < 0 ) { setVStatus( TRUE ) ; } /* It is now supposed to stick to the top left - JCJ*/
|
||||
}
|
||||
|
||||
void add_submenu ( const char *str, char *items[], puCallback _cb[],
|
||||
void *_user_data[] = NULL ) ;
|
||||
void close ( void ) ;
|
||||
} ;
|
||||
|
||||
|
||||
// Not sure what this one does ...
|
||||
class puaSelectBox : public puGroup
|
||||
{
|
||||
UL_TYPE_DATA
|
||||
|
||||
protected:
|
||||
char ** list ;
|
||||
int num_items ;
|
||||
|
||||
int curr_item ;
|
||||
|
||||
puInput *input ;
|
||||
puArrowButton *down_arrow ;
|
||||
puArrowButton *up_arrow ;
|
||||
|
||||
static void handle_arrow ( puObject *arrow ) ;
|
||||
|
||||
void update_widgets ( void ) ;
|
||||
|
||||
public:
|
||||
void newList ( char ** _list ) ;
|
||||
int getNumItems ( void ) const { return num_items ; }
|
||||
|
||||
int getCurrentItem ( void ) const { return curr_item ; }
|
||||
void setCurrentItem ( int item )
|
||||
{
|
||||
if ( ( item >= 0 ) && ( item < num_items ) )
|
||||
{
|
||||
curr_item = item ;
|
||||
update_widgets () ;
|
||||
|
||||
invokeCallback () ;
|
||||
}
|
||||
}
|
||||
|
||||
void setSize ( int w, int h ) ;
|
||||
void draw ( int dx, int dy ) ;
|
||||
int checkKey ( int key, int updown ) ;
|
||||
|
||||
virtual void setColourScheme ( float r, float g, float b, float a = 1.0f ) ;
|
||||
virtual void setColour ( int which, float r, float g, float b, float a = 1.0f ) ;
|
||||
|
||||
puaSelectBox ( int minx, int miny, int maxx, int maxy,
|
||||
char **list ) ;
|
||||
} ;
|
||||
|
||||
|
||||
// A slider with up- and down-arrows on its ends
|
||||
class puaScrollBar : public puSlider
|
||||
{
|
||||
UL_TYPE_DATA
|
||||
|
||||
protected:
|
||||
int arrow_count ;
|
||||
int active_arrow ;
|
||||
float line_step_size ;
|
||||
enum { NONE = 0, FASTDOWN = 1, DOWN = 2, UP = 4, FASTUP = 8 };
|
||||
|
||||
public:
|
||||
void doHit ( int button, int updown, int x, int y ) ;
|
||||
void draw ( int dx, int dy ) ;
|
||||
int checkHit ( int button, int updown, int x, int y ) ;
|
||||
puaScrollBar ( int minx, int miny, int sz, int arrows, int vertical = FALSE ) :
|
||||
puSlider ( minx, miny, sz, vertical )
|
||||
{
|
||||
type |= PUCLASS_SCROLLBAR ;
|
||||
arrow_count = arrows ;
|
||||
active_arrow = NONE ;
|
||||
line_step_size = 0.0f ;
|
||||
}
|
||||
|
||||
/* Alternate constructor which lets you explicitly set width */
|
||||
|
||||
puaScrollBar ( int minx, int miny, int sz, int arrows, int vertical, int width ) :
|
||||
puSlider ( minx, miny, sz, vertical, width )
|
||||
{
|
||||
type |= PUCLASS_SCROLLBAR ;
|
||||
arrow_count = arrows ;
|
||||
active_arrow = NONE ;
|
||||
line_step_size = 0.0f ;
|
||||
}
|
||||
|
||||
void setMaxValue ( float f )
|
||||
{
|
||||
maximum_value = f ;
|
||||
slider_fraction = 1.0f / ( getMaxValue() - getMinValue() + 1.0f ) ;
|
||||
puPostRefresh () ;
|
||||
}
|
||||
|
||||
|
||||
void setMinValue ( float i )
|
||||
{
|
||||
minimum_value = i ;
|
||||
slider_fraction = 1.0f / ( getMaxValue() - getMinValue() + 1.0f ) ;
|
||||
puPostRefresh () ;
|
||||
}
|
||||
|
||||
void setLineStepSize ( float s ) { line_step_size = s ; }
|
||||
float getLineStepSize ( void ) const { return line_step_size ; }
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
// A puSlider with two slide boxes instead of one
|
||||
class puaBiSlider : public puSlider
|
||||
{
|
||||
UL_TYPE_DATA
|
||||
|
||||
protected:
|
||||
float current_max ;
|
||||
float current_min ;
|
||||
|
||||
int active_button ; // Zero for none, one for min, two for max
|
||||
public:
|
||||
void doHit ( int button, int updown, int x, int y ) ;
|
||||
void draw ( int dx, int dy ) ;
|
||||
puaBiSlider ( int minx, int miny, int sz, int vertical = FALSE ) :
|
||||
puSlider ( minx, miny, sz, vertical )
|
||||
{
|
||||
type |= PUCLASS_BISLIDER ;
|
||||
setMaxValue ( 1.0f ) ;
|
||||
setMinValue ( 0.0f ) ;
|
||||
setStepSize ( 1.0f ) ;
|
||||
current_max = 1.0f ;
|
||||
current_min = 0.0f ;
|
||||
active_button = 0 ;
|
||||
}
|
||||
|
||||
/* Alternate constructor which lets you explicitly set width */
|
||||
|
||||
puaBiSlider ( int minx, int miny, int sz, int vertical, int width ) :
|
||||
puSlider ( minx, miny, sz, vertical, width )
|
||||
{
|
||||
type |= PUCLASS_BISLIDER ;
|
||||
setMaxValue ( 1.0f ) ;
|
||||
setMinValue ( 0.0f ) ;
|
||||
setStepSize ( 1.0f ) ;
|
||||
current_max = 1.0f ;
|
||||
current_min = 0.0f ;
|
||||
active_button = 0 ;
|
||||
}
|
||||
|
||||
void setMaxValue ( float i )
|
||||
{
|
||||
maximum_value = i ;
|
||||
slider_fraction = 1.0f / ( getMaxValue() - getMinValue() + 1.0f ) ;
|
||||
puPostRefresh () ;
|
||||
}
|
||||
|
||||
|
||||
void setMinValue ( float i )
|
||||
{
|
||||
minimum_value = i ;
|
||||
slider_fraction = 1.0f / ( getMaxValue() - getMinValue() + 1.0f ) ;
|
||||
puPostRefresh () ;
|
||||
}
|
||||
|
||||
void setCurrentMax ( int i ) { current_max = (float) i ; puPostRefresh () ; } /* DEPRECATED */
|
||||
void setCurrentMax ( float f ) { current_max = f ; puPostRefresh () ; }
|
||||
float getCurrentMax ( void ) const { return current_max ; }
|
||||
|
||||
void setCurrentMin ( int i ) { current_min = (float) i ; puPostRefresh () ; } /* DEPRECATED */
|
||||
void setCurrentMin ( float f ) { current_min = f ; puPostRefresh () ; }
|
||||
float getCurrentMin ( void ) const { return current_min ; }
|
||||
|
||||
void setActiveButton ( int i ) { active_button = i ; }
|
||||
int getActiveButton ( void ) const { return active_button ; }
|
||||
} ;
|
||||
|
||||
|
||||
// A puSlider with three slide boxes
|
||||
|
||||
class puaTriSlider : public puaBiSlider
|
||||
{
|
||||
UL_TYPE_DATA
|
||||
|
||||
protected:
|
||||
// "active_button" is now zero for none, one for min, two for middle, three for max
|
||||
int freeze_ends ; // true to make end sliders unmovable
|
||||
public:
|
||||
void doHit ( int button, int updown, int x, int y ) ;
|
||||
void draw ( int dx, int dy ) ;
|
||||
puaTriSlider ( int minx, int miny, int sz, int vertical = FALSE ) :
|
||||
puaBiSlider ( minx, miny, sz, vertical )
|
||||
{
|
||||
type |= PUCLASS_TRISLIDER ;
|
||||
freeze_ends = TRUE ;
|
||||
}
|
||||
|
||||
/* Alternate constructor which lets you explicitly set width */
|
||||
|
||||
puaTriSlider ( int minx, int miny, int sz, int vertical, int width ) :
|
||||
puaBiSlider ( minx, miny, sz, vertical, width )
|
||||
{
|
||||
type |= PUCLASS_TRISLIDER ;
|
||||
freeze_ends = TRUE ;
|
||||
}
|
||||
|
||||
int getFreezeEnds ( void ) const { return freeze_ends ; }
|
||||
void setFreezeEnds ( int val ) { freeze_ends = val ; puPostRefresh () ; }
|
||||
} ;
|
||||
|
||||
|
||||
// A vertical puBiSlider with a puInput box above it showing the current maximum
|
||||
// value and a puInput box below it showing the current minimum value
|
||||
|
||||
class puaBiSliderWithEnds : public puGroup
|
||||
{
|
||||
UL_TYPE_DATA
|
||||
|
||||
protected:
|
||||
puaBiSlider *slider ;
|
||||
puInput *max_box ;
|
||||
puInput *min_box ;
|
||||
|
||||
static void handle_slider ( puObject *obj ) ;
|
||||
static void handle_max ( puObject *obj ) ;
|
||||
static void handle_min ( puObject *obj ) ;
|
||||
static void input_down_callback ( puObject *obj ) ;
|
||||
|
||||
void update_widgets ( void ) ;
|
||||
|
||||
public:
|
||||
// For internal use only:
|
||||
void __setMax ( float f ) { max_box->setValue ( f ) ; }
|
||||
void __setMin ( float f ) { min_box->setValue ( f ) ; }
|
||||
|
||||
// For public use:
|
||||
|
||||
void draw ( int dx, int dy ) ;
|
||||
int checkHit ( int button, int updown, int x, int y )
|
||||
{
|
||||
return puGroup::checkHit ( button, updown, x, y ) ;
|
||||
}
|
||||
|
||||
int checkKey ( int key, int updown ) ;
|
||||
|
||||
puaBiSliderWithEnds ( int minx, int miny, int maxx, int maxy ) ;
|
||||
|
||||
void setSize ( int w, int h ) ;
|
||||
|
||||
void setMaxValue ( float f ) { slider->setMaxValue ( f ) ; }
|
||||
float getMaxValue ( void ) const { return slider->getMaxValue () ; }
|
||||
void setMinValue ( float f ) { slider->setMinValue ( f ) ; }
|
||||
float getMinValue ( void ) const { return slider->getMinValue () ; }
|
||||
|
||||
void setCurrentMax ( float f )
|
||||
{
|
||||
slider->setCurrentMax ( f ) ;
|
||||
max_box->setValue ( f ) ;
|
||||
}
|
||||
|
||||
float getCurrentMax ( void ) const { return slider->getCurrentMax () ; }
|
||||
|
||||
void setCurrentMin ( float f )
|
||||
{
|
||||
slider->setCurrentMin ( f ) ;
|
||||
min_box->setValue ( f ) ;
|
||||
}
|
||||
|
||||
float getCurrentMin ( void ) const { return slider->getCurrentMin () ; }
|
||||
|
||||
void setActiveButton ( int i ) { slider->setActiveButton ( i ) ; }
|
||||
int getActiveButton ( void ) const { return slider->getActiveButton () ; }
|
||||
|
||||
char *getValidData ( void ) const { return max_box->getValidData () ; }
|
||||
void setValidData ( char *data ) { max_box->setValidData ( data ) ; min_box->setValidData ( data ) ; }
|
||||
void addValidData ( char *data ) { max_box->addValidData ( data ) ; min_box->addValidData ( data ) ; }
|
||||
|
||||
void setCBMode ( int m ) { slider->setCBMode ( m ) ; }
|
||||
int getCBMode ( void ) const { return slider->getCBMode () ; }
|
||||
|
||||
void setDelta ( float f ) { slider->setDelta ( f ) ; }
|
||||
float getDelta ( void ) const { return slider->getDelta () ; }
|
||||
|
||||
float getStepSize ( void ) const { return slider->getStepSize () ; }
|
||||
void setStepSize ( float f ) { slider->setStepSize ( f ) ; }
|
||||
} ;
|
||||
|
||||
|
||||
// A vertical puSlider with a puInput box above or below it showing its value
|
||||
|
||||
class puaSliderWithInput : public puGroup
|
||||
{
|
||||
UL_TYPE_DATA
|
||||
|
||||
protected:
|
||||
puSlider *slider ;
|
||||
puInput *input_box ;
|
||||
int input_position ;
|
||||
|
||||
static void handle_slider ( puObject *obj ) ;
|
||||
static void handle_input ( puObject *obj ) ;
|
||||
static void input_down_callback ( puObject *obj ) ;
|
||||
|
||||
void update_widgets ( void ) ;
|
||||
|
||||
public:
|
||||
// For internal use only:
|
||||
void __setInputBox ( float f ) { input_box->setValue ( f ) ; }
|
||||
|
||||
// For public use:
|
||||
|
||||
void draw ( int dx, int dy ) ;
|
||||
int checkHit ( int button, int updown, int x, int y )
|
||||
{
|
||||
return puGroup::checkHit ( button, updown, x, y ) ;
|
||||
}
|
||||
|
||||
int checkKey ( int key, int updown ) ;
|
||||
|
||||
puaSliderWithInput ( int minx, int miny, int maxx, int maxy, int above = 0 ) ;
|
||||
|
||||
void setSize ( int w, int h ) ;
|
||||
|
||||
void setMaxValue ( float f ) { slider->setMaxValue ( f ) ; }
|
||||
float getMaxValue ( void ) const { return slider->getMaxValue () ; }
|
||||
void setMinValue ( float f ) { slider->setMinValue ( f ) ; }
|
||||
float getMinValue ( void ) const { return slider->getMinValue () ; }
|
||||
|
||||
void setValue ( int i ) { slider->setValue ( i ) ; input_box->setValue ( i ) ; }
|
||||
void setValue ( float f ) { slider->setValue ( f ) ; input_box->setValue ( f ) ; }
|
||||
virtual void setValue ( const char *s ) { slider->setValue ( s ) ; }
|
||||
virtual void setValue ( bool b ) { slider->setValue ( b ) ; }
|
||||
|
||||
int getIntegerValue ( void ) { return slider->getIntegerValue () ; }
|
||||
float getFloatValue ( void ) { return slider->getFloatValue () ; }
|
||||
char getCharValue ( void ) { return slider->getCharValue () ; }
|
||||
char *getStringValue ( void ) { return slider->getStringValue () ; }
|
||||
bool getBooleanValue ( void ) { return slider->getBooleanValue () ; }
|
||||
|
||||
char *getValidData ( void ) const { return input_box->getValidData () ; }
|
||||
void setValidData ( char *data ) { input_box->setValidData ( data ) ; }
|
||||
void addValidData ( char *data ) { input_box->addValidData ( data ) ; }
|
||||
|
||||
void setCBMode ( int m ) { slider->setCBMode ( m ) ; }
|
||||
int getCBMode ( void ) const { return slider->getCBMode () ; }
|
||||
|
||||
void setDelta ( float f ) { slider->setDelta ( f ) ; }
|
||||
float getDelta ( void ) const { return slider->getDelta () ; }
|
||||
|
||||
float getStepSize ( void ) const { return slider->getStepSize () ; }
|
||||
void setStepSize ( float f ) { slider->setStepSize ( f ) ; }
|
||||
} ;
|
||||
|
||||
class puaSpinBox : public puRange, public puGroup
|
||||
{
|
||||
UL_TYPE_DATA
|
||||
|
||||
protected :
|
||||
puInput *input_box ;
|
||||
puArrowButton *up_arrow ;
|
||||
puArrowButton *down_arrow ;
|
||||
|
||||
int arrow_position ;
|
||||
|
||||
public :
|
||||
/* Whether the arrows are on the LEFT of the input box (0) or RIGHT (1 DEFAULT) */
|
||||
int getArrowPosition ( void ) const { return arrow_position ; }
|
||||
/* Offered as a proportion of the input box height. Default = 0.5 */
|
||||
void setArrowHeight ( float height )
|
||||
{
|
||||
puBox ibox = *(input_box->getABox()) ;
|
||||
int size = int(height * ( ibox.max[1] - ibox.min[1] )) ;
|
||||
up_arrow->setSize ( size, size ) ;
|
||||
down_arrow->setSize ( size, size ) ;
|
||||
int xpos = getArrowPosition () ? ibox.max[0] : ibox.min[0] - size ;
|
||||
int ymid = ( ibox.max[1] + ibox.min[1] ) / 2 ;
|
||||
if ( getArrowPosition () == 0 ) /* Arrows are on the left, adjust the x-position of the input box */
|
||||
{
|
||||
ibox.min[0] -= xpos ;
|
||||
input_box->setPosition ( ibox.min[0], ibox.min[1] ) ;
|
||||
abox.min[0] += xpos ;
|
||||
xpos = 0 ;
|
||||
}
|
||||
|
||||
if ( height > 0.5f ) /* Adjust the input box to be up from the bottom */
|
||||
{
|
||||
input_box->setPosition ( ibox.min[0], ibox.min[1] + size - ymid ) ;
|
||||
abox.min[1] += ymid - size ;
|
||||
ymid = size ;
|
||||
}
|
||||
else /* Input box is at the bottom of the group area */
|
||||
{
|
||||
input_box->setPosition ( ibox.min[0], 0 ) ;
|
||||
abox.min[1] += ibox.min[1] ;
|
||||
}
|
||||
|
||||
up_arrow->setPosition ( xpos, ymid ) ;
|
||||
down_arrow->setPosition ( xpos, ymid - size ) ;
|
||||
recalc_bbox() ;
|
||||
}
|
||||
|
||||
float getArrowHeight ( void ) const
|
||||
{
|
||||
int awid, ahgt, iwid, ihgt ;
|
||||
input_box->getSize ( &iwid, &ihgt ) ;
|
||||
up_arrow->getSize ( &awid, &ahgt ) ;
|
||||
return float(ahgt) / float(ihgt) ;
|
||||
}
|
||||
|
||||
puaSpinBox ( int minx, int miny, int maxx, int maxy, int arrow_pos = 1 ) ;
|
||||
|
||||
void setValue ( float f ) { puValue::setValue ( f ) ; input_box->setValue ( f ) ; }
|
||||
void setValue ( int i ) { puValue::setValue ( i ) ; input_box->setValue ( i ) ; }
|
||||
void setValue ( const char *s ) { puValue::setValue ( s ) ; input_box->setValue ( s ) ; }
|
||||
void setValue ( puValue *pv ) { puValue::setValue ( pv ) ; input_box->setValue ( pv ) ; }
|
||||
} ;
|
||||
|
||||
|
||||
/*
|
||||
* Widget that looks like a 3-d coordinate system with quarter-circles in the coordinate planes.
|
||||
* It is used in 3-d modeling to translate and rotate the scene. The coordinates rotate with
|
||||
* the scene but do not translate. Defined values are:
|
||||
* 0 - Nothing active
|
||||
* 1 - Dot at origin active: reset (usually)
|
||||
* 2 - X-axis dot active: rotate about y- and z-axes
|
||||
* 3 - Y-axis dot active: rotate about z- and x-axes
|
||||
* 4 - Z-axis dot active: rotate about x- and y-axes
|
||||
* 5 - X-axis bar active: translate along x-axis
|
||||
* 6 - Y-axis bar active: translate along y-axis
|
||||
* 7 - Z-axis bar active: translate along z-axis
|
||||
* 8 - XY-plane arc active: rotate about z-axis
|
||||
* 9 - YZ-plane arc active: rotate about x-axis
|
||||
* 10 - ZX-plane arc active: rotate about y-axis
|
||||
* 11 - X-axis, Y-axis, and XY-arc active: translate in xy-plane
|
||||
* 12 - Y-axis, Z-axis, and YZ-arc active: translate in yz-plane
|
||||
* 13 - Z-axis, X-axis, and ZX-arc active: translate in zx-plane
|
||||
*/
|
||||
#define PUACOMPASS_INACTIVE 0
|
||||
#define PUACOMPASS_RESET 1
|
||||
#define PUACOMPASS_ROTATE_Y_Z 2
|
||||
#define PUACOMPASS_ROTATE_Z_X 3
|
||||
#define PUACOMPASS_ROTATE_X_Y 4
|
||||
#define PUACOMPASS_TRANSLATE_X 5
|
||||
#define PUACOMPASS_TRANSLATE_Y 6
|
||||
#define PUACOMPASS_TRANSLATE_Z 7
|
||||
#define PUACOMPASS_ROTATE_Z 8
|
||||
#define PUACOMPASS_ROTATE_X 9
|
||||
#define PUACOMPASS_ROTATE_Y 10
|
||||
#define PUACOMPASS_TRANSLATE_X_Y 11
|
||||
#define PUACOMPASS_TRANSLATE_Y_Z 12
|
||||
#define PUACOMPASS_TRANSLATE_Z_X 13
|
||||
|
||||
class puaCompass : public puObject
|
||||
{
|
||||
UL_TYPE_DATA
|
||||
|
||||
protected :
|
||||
sgQuat rotation ;
|
||||
sgVec3 translation ;
|
||||
float point_size ;
|
||||
int button_state ;
|
||||
int trigger_button ;
|
||||
float mouse_x, mouse_y, mouse_z ;
|
||||
float translation_sensitivity ;
|
||||
|
||||
float xint, yint, zint ;
|
||||
float prev_angle ;
|
||||
sgQuat prev_rotation ;
|
||||
|
||||
public :
|
||||
puaCompass ( int minx, int miny, int maxx, int maxy ) : puObject ( minx, miny, maxx, maxy )
|
||||
{
|
||||
setValue ( PUACOMPASS_INACTIVE ) ;
|
||||
|
||||
// sgSetQuat ( rotation, 1.0f, 0.0f, 0.0f, 0.0f ) ;
|
||||
// sgSetQuat ( rotation, 0.707107f, 0.707107f, 0.0f, 0.0f ) ;
|
||||
// sgSetQuat ( rotation, 0.5f, -0.5f, 0.5f, 0.5f ) ;
|
||||
// sgSetQuat ( rotation, 0.866025f, -0.166667f, 0.166667f, 0.166667f ) ;
|
||||
sgSetQuat ( rotation, 0.866025f, -0.408248f, 0.288675f, 0.0f ) ;
|
||||
sgSetVec3 ( translation, 0.0f, 0.0f, 0.0f ) ;
|
||||
|
||||
point_size = 10.0f ;
|
||||
|
||||
button_state = PU_UP ;
|
||||
trigger_button = active_mouse_button ;
|
||||
mouse_x = mouse_y = mouse_z = 0.0f ;
|
||||
translation_sensitivity = 1.0f ;
|
||||
|
||||
xint = yint = zint = 0.0f ;
|
||||
prev_angle = 0.0f ;
|
||||
sgCopyQuat ( prev_rotation, rotation ) ;
|
||||
}
|
||||
|
||||
void draw ( int dx, int dy ) ;
|
||||
void doHit ( int button, int updown, int x, int y ) ;
|
||||
|
||||
// Accessors and mutators
|
||||
void getRotation ( sgQuat q ) const { memcpy ( q, rotation, 4 * sizeof(sgFloat) ) ; }
|
||||
void setRotation ( sgQuat q ) { memcpy ( rotation, q, 4 * sizeof(sgFloat) ) ; }
|
||||
void setRotation ( sgFloat t, sgFloat x, sgFloat y, sgFloat z )
|
||||
{
|
||||
sgFloat sinth = sgSin ( t / 2.0f ) ;
|
||||
sgFloat norm = sgSqrt ( x * x + y * y + z * z ) ;
|
||||
if ( norm == 0.0 ) norm = 1.0 ;
|
||||
rotation[SG_W] = sgCos ( t / 2.0f ) ;
|
||||
rotation[SG_X] = sinth * x / norm ;
|
||||
rotation[SG_Y] = sinth * y / norm ;
|
||||
rotation[SG_Z] = sinth * z / norm ;
|
||||
}
|
||||
|
||||
void getTranslation ( sgVec3 t ) const { memcpy ( t, translation, 3 * sizeof(sgFloat) ) ; }
|
||||
void setTranslation ( sgVec3 t ) { memcpy ( translation, t, 3 * sizeof(sgFloat) ) ; }
|
||||
void setTranslation ( sgFloat x, sgFloat y, sgFloat z ) { translation[SG_X] = x ; translation[SG_Y] = y ; translation[SG_Z] = z ; }
|
||||
|
||||
float getPointSize () const { return point_size ; }
|
||||
void setPointSize ( float p ) { point_size = p ; }
|
||||
|
||||
int getTriggerButton () const { return trigger_button ; }
|
||||
void setTriggerButton ( int b ) { trigger_button = b ; }
|
||||
|
||||
float getTranslationSensitivity () const { return translation_sensitivity ; }
|
||||
void setTranslationSensitivity ( float t ) { translation_sensitivity = t ; }
|
||||
} ;
|
||||
|
||||
|
||||
class puaChooser
|
||||
{
|
||||
UL_TYPE_DATA
|
||||
|
||||
puButton *chooser_button ;
|
||||
puPopupMenu *popup_menu ;
|
||||
|
||||
int x1, y1, x2, y2 ;
|
||||
|
||||
static void static_popup_cb ( puObject * ) ;
|
||||
static void static_menu_cb ( puObject * ) ;
|
||||
|
||||
public:
|
||||
|
||||
virtual ~puaChooser ()
|
||||
{
|
||||
delete chooser_button ;
|
||||
delete popup_menu ;
|
||||
}
|
||||
|
||||
puaChooser ( int _x1, int _y1, int _x2, int _y2, char *legend ) ;
|
||||
|
||||
void add_item ( char *str, puCallback _cb, void *_user_data = NULL ) ;
|
||||
void close () ;
|
||||
|
||||
void popup_cb () ;
|
||||
|
||||
void menuCleanup ( const char *s ) ;
|
||||
|
||||
void hide () { chooser_button -> hide () ; popup_menu -> hide () ; }
|
||||
void reveal () { chooser_button -> reveal () ; popup_menu -> hide () ; }
|
||||
|
||||
static void menuCleanup ( puObject * ) ;
|
||||
} ;
|
||||
|
||||
|
||||
/**
|
||||
* A scrolling list for PUI.
|
||||
*
|
||||
* Believe it or not, PUI does not have one of these.
|
||||
*
|
||||
* This widget consists of a puListBox, a slider and two
|
||||
* arrow buttons. This makes the ListBox scrollable,
|
||||
* very handy if the box is too small to show all items
|
||||
* at once.
|
||||
*
|
||||
* (Original code taken from FlightGear 0.9.6 sources,
|
||||
* modified by Jan Reucker)
|
||||
*/
|
||||
class puaList : public puGroup
|
||||
{
|
||||
UL_TYPE_DATA
|
||||
|
||||
char ** _contents;
|
||||
puFrame * _frame;
|
||||
puSlider * _slider;
|
||||
puArrowButton * _up_arrow;
|
||||
puArrowButton * _down_arrow;
|
||||
int _style;
|
||||
int _sw; // slider width
|
||||
int _width, _height;
|
||||
|
||||
protected:
|
||||
virtual void init (int w, int h, short transparent);
|
||||
puListBox * _list_box;
|
||||
|
||||
public:
|
||||
puaList (int x, int y, int w, int h, int sl_width = 20);
|
||||
puaList (int x, int y, int w, int h, char ** contents, int sl_width = 20);
|
||||
puaList (int x, int y, int w, int h, short transparent, int sl_width = 20);
|
||||
puaList (int x, int y, int w, int h, short transparent, char ** contents, int sl_width = 20);
|
||||
virtual ~puaList ();
|
||||
|
||||
virtual void newList (char ** contents);
|
||||
|
||||
virtual char * getStringValue ();
|
||||
virtual int getIntegerValue ();
|
||||
virtual void getValue (char **ps);
|
||||
virtual void getValue (int *i);
|
||||
|
||||
virtual void setColourScheme (float r, float g, float b, float a);
|
||||
virtual void setColour (int which, float r, float g, float b, float a);
|
||||
virtual void setSize (int w, int h);
|
||||
|
||||
int checkHit ( int button, int updown, int x, int y );
|
||||
int getNumVisible ( void ) const { return _list_box->getNumVisible(); }
|
||||
int getNumItems ( void ) const { return _list_box->getNumItems(); }
|
||||
int getTopItem ( void ) const { return _list_box->getTopItem(); }
|
||||
void setTopItem ( int item_index );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
4
include/plib/puAuxLocal.h
Normal file
4
include/plib/puAuxLocal.h
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
#define PU_USE_NONE 1
|
||||
#include "puAux.h"
|
||||
|
||||
68
include/plib/puFLTK.h
Normal file
68
include/plib/puFLTK.h
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
PLIB - A Suite of Portable Game Libraries
|
||||
Copyright (C) 1998,2002 Steve Baker
|
||||
|
||||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information visit http://plib.sourceforge.net
|
||||
|
||||
$Id: puFLTK.h 1857 2004-02-16 13:49:03Z stromberg $
|
||||
*/
|
||||
|
||||
#ifndef _PU_FLTK_H_
|
||||
#define _PU_FLTK_H_
|
||||
|
||||
#ifndef PU_USE_FLTK
|
||||
# define PU_USE_FLTK
|
||||
#endif
|
||||
|
||||
#include "pu.h"
|
||||
#include <FL/Fl_Gl_Window.H>
|
||||
|
||||
|
||||
inline int puGetWindowFLTK ()
|
||||
{
|
||||
return (int) Fl_Window::current () ;
|
||||
}
|
||||
|
||||
inline void puSetWindowFLTK ( int window )
|
||||
{
|
||||
((Fl_Gl_Window *) window) -> make_current () ;
|
||||
}
|
||||
|
||||
inline void puGetWindowSizeFLTK ( int *width, int *height )
|
||||
{
|
||||
Fl_Window * window = Fl_Window::current () ;
|
||||
*width = window->w() ;
|
||||
*height = window->h() ;
|
||||
}
|
||||
|
||||
inline void puSetWindowSizeFLTK ( int width, int height )
|
||||
{
|
||||
Fl_Window * window = Fl_Window::current () ;
|
||||
window -> resize ( window->x(), window->y(), width, height ) ;
|
||||
}
|
||||
|
||||
inline void puInitFLTK ()
|
||||
{
|
||||
puSetWindowFuncs ( puGetWindowFLTK,
|
||||
puSetWindowFLTK,
|
||||
puGetWindowSizeFLTK,
|
||||
puSetWindowSizeFLTK ) ;
|
||||
puRealInit () ;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
75
include/plib/puGLUT.h
Normal file
75
include/plib/puGLUT.h
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
PLIB - A Suite of Portable Game Libraries
|
||||
Copyright (C) 1998,2002 Steve Baker
|
||||
|
||||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information visit http://plib.sourceforge.net
|
||||
|
||||
$Id: puGLUT.h 2122 2007-09-15 12:34:36Z fayjf $
|
||||
*/
|
||||
|
||||
#ifndef _PU_GLUT_H_
|
||||
#define _PU_GLUT_H_
|
||||
|
||||
#ifndef PU_USE_GLUT
|
||||
# define PU_USE_GLUT
|
||||
#endif
|
||||
|
||||
#include "pu.h"
|
||||
|
||||
#ifdef UL_MAC_OSX
|
||||
# include <GLUT/glut.h>
|
||||
#else
|
||||
# ifdef FREEGLUT_IS_PRESENT /* for FreeGLUT like PLIB 1.6.1*/
|
||||
# include <GL/freeglut.h>
|
||||
# else
|
||||
# include <GL/glut.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
inline int puGetWindowGLUT()
|
||||
{
|
||||
return glutGetWindow () ;
|
||||
}
|
||||
|
||||
inline void puSetWindowGLUT ( int window )
|
||||
{
|
||||
glutSetWindow ( window ) ;
|
||||
}
|
||||
|
||||
inline void puGetWindowSizeGLUT ( int *width, int *height )
|
||||
{
|
||||
*width = glutGet ( (GLenum) GLUT_WINDOW_WIDTH ) ;
|
||||
*height = glutGet ( (GLenum) GLUT_WINDOW_HEIGHT ) ;
|
||||
}
|
||||
|
||||
inline void puSetWindowSizeGLUT ( int width, int height )
|
||||
{
|
||||
glutReshapeWindow ( width, height ) ;
|
||||
}
|
||||
|
||||
inline void puInitGLUT ()
|
||||
{
|
||||
puSetWindowFuncs ( puGetWindowGLUT,
|
||||
puSetWindowGLUT,
|
||||
puGetWindowSizeGLUT,
|
||||
puSetWindowSizeGLUT ) ;
|
||||
puRealInit () ;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
101
include/plib/puNative.h
Normal file
101
include/plib/puNative.h
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
PLIB - A Suite of Portable Game Libraries
|
||||
Copyright (C) 1998,2002 Steve Baker
|
||||
|
||||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information visit http://plib.sourceforge.net
|
||||
|
||||
$Id: puNative.h 1857 2004-02-16 13:49:03Z stromberg $
|
||||
*/
|
||||
|
||||
#ifndef _PU_NATIVE_H_
|
||||
#define _PU_NATIVE_H_
|
||||
|
||||
#ifndef PU_USE_NATIVE
|
||||
# define PU_USE_NATIVE
|
||||
#endif
|
||||
|
||||
#include "pu.h"
|
||||
|
||||
#if defined(UL_GLX)
|
||||
# include <GL/glx.h>
|
||||
#elif defined(UL_WGL)
|
||||
// nothing
|
||||
#elif defined(UL_AGL)
|
||||
# include <agl.h>
|
||||
#elif defined(UL_CGL)
|
||||
# include <OpenGL/CGLCurrent.h>
|
||||
#endif
|
||||
|
||||
|
||||
inline int puGetWindowNative ()
|
||||
{
|
||||
#if defined(UL_GLX)
|
||||
return (int) glXGetCurrentDrawable () ;
|
||||
#elif defined(UL_WGL)
|
||||
return (int) wglGetCurrentDC () ;
|
||||
#elif defined(UL_AGL)
|
||||
return (int) aglGetCurrentDrawable () ;
|
||||
#elif defined(UL_CGL)
|
||||
return (int) CGLGetCurrentContext () ;
|
||||
#else
|
||||
return 0 ;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
inline void puGetWindowSizeNative ( int *width, int *height )
|
||||
{
|
||||
#if defined(UL_GLX)
|
||||
|
||||
Window root ;
|
||||
int x, y ;
|
||||
unsigned int w, h, b, d ;
|
||||
|
||||
XGetGeometry ( glXGetCurrentDisplay (),
|
||||
glXGetCurrentDrawable (),
|
||||
&root, &x, &y, &w, &h, &b, &d ) ;
|
||||
*width = w ;
|
||||
*height = h ;
|
||||
|
||||
#elif defined(UL_WGL)
|
||||
|
||||
RECT r ;
|
||||
GetClientRect( WindowFromDC( wglGetCurrentDC() ), &r );
|
||||
*width = r.right ;
|
||||
*height = r.bottom ;
|
||||
|
||||
#else // Help! Need implementations for more systems.
|
||||
|
||||
GLint vp[4] ;
|
||||
glGetIntegerv ( GL_VIEWPORT, vp ) ;
|
||||
*width = vp[0] + vp[2] ;
|
||||
*height = vp[1] + vp[3] ;
|
||||
// Note: puSetOpenGLState calls glViewport(0, 0, w, h).
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
inline void puInitNative ()
|
||||
{
|
||||
puSetWindowFuncs ( puGetWindowNative, NULL,
|
||||
puGetWindowSizeNative, NULL ) ;
|
||||
puRealInit () ;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
66
include/plib/puPW.h
Normal file
66
include/plib/puPW.h
Normal file
@@ -0,0 +1,66 @@
|
||||
|
||||
/*
|
||||
PLIB - A Suite of Portable Game Libraries
|
||||
Copyright (C) 1998,2002 Steve Baker
|
||||
|
||||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information visit http://plib.sourceforge.net
|
||||
|
||||
$Id: puPW.h 1863 2004-02-17 01:43:21Z sjbaker $
|
||||
*/
|
||||
|
||||
#ifndef _PU_PW_H_
|
||||
#define _PU_PW_H_
|
||||
|
||||
#include "pu.h"
|
||||
|
||||
#define PUPW_WINDOW_MAGIC 0x3DEB4938 /* Random! */
|
||||
|
||||
inline int puGetWindowPW()
|
||||
{
|
||||
return PUPW_WINDOW_MAGIC ;
|
||||
}
|
||||
|
||||
inline void puSetWindowPW ( int window )
|
||||
{
|
||||
// Not possible because PW is a single-window library.
|
||||
// But we can at least check that the handle matches.
|
||||
|
||||
assert ( window == PUPW_WINDOW_MAGIC ) ;
|
||||
}
|
||||
|
||||
inline void puGetWindowSizePW ( int *width, int *height )
|
||||
{
|
||||
pwGetSize ( width, height ) ;
|
||||
}
|
||||
|
||||
inline void puSetWindowSizePW ( int width, int height )
|
||||
{
|
||||
pwSetSize ( width, height ) ;
|
||||
}
|
||||
|
||||
inline void puInitPW ()
|
||||
{
|
||||
puSetWindowFuncs ( puGetWindowPW,
|
||||
puSetWindowPW,
|
||||
puGetWindowSizePW,
|
||||
puSetWindowSizePW ) ;
|
||||
puRealInit () ;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
55
include/plib/puSDL.h
Normal file
55
include/plib/puSDL.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
PLIB - A Suite of Portable Game Libraries
|
||||
Copyright (C) 1998,2002 Steve Baker
|
||||
|
||||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information visit http://plib.sourceforge.net
|
||||
|
||||
$Id: puSDL.h 2130 2007-11-18 21:46:37Z fayjf $
|
||||
*/
|
||||
|
||||
#ifndef _PU_SDL_H_
|
||||
#define _PU_SDL_H_
|
||||
|
||||
#ifndef PU_USE_SDL
|
||||
# define PU_USE_SDL
|
||||
#endif
|
||||
|
||||
#include "pu.h"
|
||||
#include "SDL.h"
|
||||
|
||||
|
||||
inline int puGetWindowSDL ()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline void puGetWindowSizeSDL ( int *width, int *height )
|
||||
{
|
||||
SDL_Surface *display = SDL_GetVideoSurface () ;
|
||||
*width = display->w ;
|
||||
*height = display->h ;
|
||||
}
|
||||
|
||||
inline void puInitSDL ()
|
||||
{
|
||||
puSetWindowFuncs ( puGetWindowSDL, NULL,
|
||||
puGetWindowSizeSDL, NULL ) ;
|
||||
puRealInit () ;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
3102
include/plib/sg.h
Normal file
3102
include/plib/sg.h
Normal file
File diff suppressed because it is too large
Load Diff
851
include/plib/ul.h
Normal file
851
include/plib/ul.h
Normal file
@@ -0,0 +1,851 @@
|
||||
/*
|
||||
PLIB - A Suite of Portable Game Libraries
|
||||
Copyright (C) 1998,2002 Steve Baker
|
||||
|
||||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information visit http://plib.sourceforge.net
|
||||
|
||||
$Id: ul.h 2131 2008-03-11 02:23:50Z sjbaker $
|
||||
*/
|
||||
|
||||
//
|
||||
// UL - utility library
|
||||
//
|
||||
// Contains:
|
||||
// - necessary system includes
|
||||
// - basic types
|
||||
// - error message routines
|
||||
// - high performance clocks
|
||||
// - ulList
|
||||
// - ulLinkedList
|
||||
// - more to come (endian support, version ID)
|
||||
//
|
||||
|
||||
#ifndef _INCLUDED_UL_H_
|
||||
#define _INCLUDED_UL_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <assert.h>
|
||||
|
||||
/**********************\
|
||||
* *
|
||||
* Determine OS type *
|
||||
* *
|
||||
\**********************/
|
||||
|
||||
#if defined(__CYGWIN__)
|
||||
|
||||
#define UL_WIN32 1
|
||||
#define UL_CYGWIN 1 /* Windoze AND Cygwin. */
|
||||
|
||||
#elif defined(_WIN32) || defined(__WIN32__) || defined(_MSC_VER)
|
||||
|
||||
#define UL_WIN32 1
|
||||
#define UL_MSVC 1 /* Windoze AND MSVC. */
|
||||
|
||||
#elif defined(__BEOS__)
|
||||
|
||||
#define UL_BEOS 1
|
||||
|
||||
#elif defined( macintosh )
|
||||
|
||||
#define UL_MACINTOSH 1
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
|
||||
#define UL_MAC_OSX 1
|
||||
|
||||
#elif defined(__linux__)
|
||||
|
||||
#define UL_LINUX 1
|
||||
|
||||
#elif defined(__sgi)
|
||||
|
||||
#define UL_IRIX 1
|
||||
|
||||
#elif defined(_AIX)
|
||||
|
||||
#define UL_AIX 1
|
||||
|
||||
#elif defined(SOLARIS) || defined(sun)
|
||||
|
||||
#define UL_SOLARIS 1
|
||||
|
||||
#elif defined(hpux)
|
||||
|
||||
#define UL_HPUX 1
|
||||
|
||||
#elif (defined(__unix__) || defined(unix)) && !defined(USG)
|
||||
|
||||
#define UL_BSD 1
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
Add specialised includes/defines...
|
||||
*/
|
||||
|
||||
#ifdef UL_WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <mmsystem.h>
|
||||
#include <regstr.h>
|
||||
#define UL_WGL 1
|
||||
#endif
|
||||
|
||||
#ifdef UL_CYGWIN
|
||||
#include <unistd.h>
|
||||
#define UL_WGL 1
|
||||
#endif
|
||||
|
||||
#ifdef UL_BEOS
|
||||
#include <be/kernel/image.h>
|
||||
#define UL_GLX 1
|
||||
#endif
|
||||
|
||||
#ifdef UL_MACINTOSH
|
||||
#include <CodeFragments.h>
|
||||
#include <unistd.h>
|
||||
#define UL_AGL 1
|
||||
#endif
|
||||
|
||||
#ifdef UL_MAC_OSX
|
||||
#include <unistd.h>
|
||||
#define UL_CGL 1
|
||||
#endif
|
||||
|
||||
#if defined(UL_LINUX) || defined(UL_BSD) || defined(UL_IRIX) || defined(UL_SOLARIS) || defined(UL_AIX)
|
||||
#include <unistd.h>
|
||||
#include <dlfcn.h>
|
||||
#include <fcntl.h>
|
||||
#define UL_GLX 1
|
||||
#endif
|
||||
|
||||
#if defined(UL_BSD)
|
||||
#include <sys/param.h>
|
||||
#define UL_GLX 1
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
#include <errno.h>
|
||||
|
||||
/* PLIB version macros */
|
||||
|
||||
#define PLIB_MAJOR_VERSION 1
|
||||
#define PLIB_MINOR_VERSION 8
|
||||
#define PLIB_TINY_VERSION 5
|
||||
|
||||
#define PLIB_VERSION (PLIB_MAJOR_VERSION*100 \
|
||||
+PLIB_MINOR_VERSION*10 \
|
||||
+PLIB_TINY_VERSION)
|
||||
|
||||
/* SGI machines seem to suffer from a lack of FLT_EPSILON so... */
|
||||
|
||||
#ifndef FLT_EPSILON
|
||||
#define FLT_EPSILON 1.19209290e-07f
|
||||
#endif
|
||||
|
||||
#ifndef DBL_EPSILON
|
||||
#define DBL_EPSILON 1.19209290e-07f
|
||||
#endif
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
/* SUNWspro 4.2 and earlier need bool to be defined */
|
||||
|
||||
#if defined(__SUNPRO_CC) && __SUNPRO_CC < 0x500
|
||||
typedef int bool ;
|
||||
const int true = 1 ;
|
||||
const int false = 0 ;
|
||||
#endif
|
||||
|
||||
/* Let's define our own "min" and "max" so that different operating systems
|
||||
* don't complain
|
||||
*/
|
||||
#define ulMax(a,b) ((a)>(b)?(a):(b))
|
||||
#define ulMin(a,b) ((a)<(b)?(a):(b))
|
||||
|
||||
|
||||
/*
|
||||
Basic Types
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
High precision clocks.
|
||||
*/
|
||||
|
||||
class ulClock
|
||||
{
|
||||
double start ;
|
||||
double now ;
|
||||
double delta ;
|
||||
double last_time ;
|
||||
double max_delta ;
|
||||
|
||||
#ifdef UL_WIN32
|
||||
static double res ;
|
||||
static int perf_timer ;
|
||||
void initPerformanceTimer () ;
|
||||
#endif
|
||||
|
||||
double getRawTime () const ;
|
||||
|
||||
public:
|
||||
|
||||
ulClock () { reset () ; }
|
||||
|
||||
void reset ()
|
||||
{
|
||||
#ifdef UL_WIN32
|
||||
initPerformanceTimer () ;
|
||||
#endif
|
||||
start = getRawTime () ;
|
||||
now = 0.0 ;
|
||||
max_delta = 0.2 ;
|
||||
delta = 0.0000001 ; /* Faked so stoopid programs won't div0 */
|
||||
last_time = 0.0 ;
|
||||
}
|
||||
|
||||
void setMaxDelta ( double maxDelta ) { max_delta = maxDelta ; }
|
||||
double getMaxDelta () const { return max_delta ; }
|
||||
void update () ;
|
||||
double getAbsTime () const { return now ; }
|
||||
double getDeltaTime () const { return delta ; }
|
||||
double getFrameRate () const { return 1.0 / delta ; }
|
||||
} ;
|
||||
|
||||
|
||||
inline void ulSleep ( int seconds )
|
||||
{
|
||||
if ( seconds >= 0 )
|
||||
{
|
||||
#ifdef UL_WIN32
|
||||
Sleep ( 1000 * seconds ) ;
|
||||
#else
|
||||
sleep ( seconds ) ;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline void ulMilliSecondSleep ( int milliseconds )
|
||||
{
|
||||
if ( milliseconds >= 0 )
|
||||
{
|
||||
#ifdef UL_WIN32
|
||||
Sleep ( milliseconds ) ;
|
||||
#else
|
||||
usleep ( milliseconds * 1000 ) ;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
This is extern C to enable 'configure.in' to
|
||||
find it with a C-coded probe.
|
||||
*/
|
||||
|
||||
extern "C" void ulInit () ;
|
||||
|
||||
/*
|
||||
Error handler.
|
||||
*/
|
||||
|
||||
enum ulSeverity
|
||||
{
|
||||
UL_DEBUG, // Messages that can safely be ignored.
|
||||
UL_WARNING, // Messages that are important.
|
||||
UL_FATAL, // Errors that we cannot recover from.
|
||||
UL_MAX_SEVERITY
|
||||
} ;
|
||||
|
||||
|
||||
typedef void (*ulErrorCallback) ( enum ulSeverity severity, char* msg ) ;
|
||||
|
||||
void ulSetError ( enum ulSeverity severity, const char *fmt, ... ) ;
|
||||
char* ulGetError ( void ) ;
|
||||
void ulClearError ( void ) ;
|
||||
ulErrorCallback ulGetErrorCallback ( void ) ;
|
||||
void ulSetErrorCallback ( ulErrorCallback cb ) ;
|
||||
|
||||
/*
|
||||
Directory Reading
|
||||
*/
|
||||
|
||||
#define UL_NAME_MAX 256
|
||||
typedef struct _ulDir ulDir ;
|
||||
struct ulDirEnt
|
||||
{
|
||||
char d_name [ UL_NAME_MAX+1 ];
|
||||
bool d_isdir ;
|
||||
} ;
|
||||
|
||||
int ulIsAbsolutePathName ( const char *pathname ) ;
|
||||
char *ulGetCWD ( char *result, int maxlength ) ;
|
||||
|
||||
ulDir* ulOpenDir ( const char* dirname ) ;
|
||||
ulDirEnt* ulReadDir ( ulDir* dir ) ;
|
||||
void ulCloseDir ( ulDir* dir ) ;
|
||||
|
||||
// file handling
|
||||
|
||||
char* ulMakePath( char* path, const char* dir, const char* fname );
|
||||
|
||||
bool ulFileExists ( const char *fileName ) ;
|
||||
|
||||
void ulFindFile( char *filenameOutput, const char *path,
|
||||
const char * tfnameInput, const char *sAPOM ) ;
|
||||
|
||||
|
||||
/*
|
||||
Endian handling
|
||||
*/
|
||||
|
||||
static const int _ulEndianTest = 1;
|
||||
#define ulIsLittleEndian (*((char *) &_ulEndianTest ) != 0)
|
||||
#define ulIsBigEndian (*((char *) &_ulEndianTest ) == 0)
|
||||
|
||||
inline void ulEndianSwap(unsigned int *x)
|
||||
{
|
||||
*x = (( *x >> 24 ) & 0x000000FF ) |
|
||||
(( *x >> 8 ) & 0x0000FF00 ) |
|
||||
(( *x << 8 ) & 0x00FF0000 ) |
|
||||
(( *x << 24 ) & 0xFF000000 ) ;
|
||||
}
|
||||
|
||||
|
||||
inline void ulEndianSwap(unsigned short *x)
|
||||
{
|
||||
*x = (( *x >> 8 ) & 0x00FF ) |
|
||||
(( *x << 8 ) & 0xFF00 ) ;
|
||||
}
|
||||
|
||||
|
||||
inline void ulEndianSwap(float *x) { ulEndianSwap((unsigned int *)x); }
|
||||
inline void ulEndianSwap(int *x) { ulEndianSwap((unsigned int *)x); }
|
||||
inline void ulEndianSwap(short *x) { ulEndianSwap((unsigned short *)x); }
|
||||
|
||||
|
||||
inline unsigned short ulEndianLittle16(unsigned short x) {
|
||||
if (ulIsLittleEndian) {
|
||||
return x;
|
||||
} else {
|
||||
ulEndianSwap(&x);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
inline unsigned int ulEndianLittle32(unsigned int x) {
|
||||
if (ulIsLittleEndian) {
|
||||
return x;
|
||||
} else {
|
||||
ulEndianSwap(&x);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
inline float ulEndianLittleFloat(float x) {
|
||||
if (ulIsLittleEndian) {
|
||||
return x;
|
||||
} else {
|
||||
ulEndianSwap(&x);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
inline void ulEndianLittleArray16(unsigned short *x, int length) {
|
||||
if (ulIsLittleEndian) {
|
||||
return;
|
||||
} else {
|
||||
for (int i = 0; i < length; i++) {
|
||||
ulEndianSwap(x++);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void ulEndianLittleArray32(unsigned int *x, int length) {
|
||||
if (ulIsLittleEndian) {
|
||||
return;
|
||||
} else {
|
||||
for (int i = 0; i < length; i++) {
|
||||
ulEndianSwap(x++);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void ulEndianLittleArrayFloat(float *x, int length) {
|
||||
if (ulIsLittleEndian) {
|
||||
return;
|
||||
} else {
|
||||
for (int i = 0; i < length; i++) {
|
||||
ulEndianSwap(x++);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void ulEndianBigArray16(unsigned short *x, int length) {
|
||||
if (ulIsBigEndian) {
|
||||
return;
|
||||
} else {
|
||||
for (int i = 0; i < length; i++) {
|
||||
ulEndianSwap(x++);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void ulEndianBigArray32(unsigned int *x, int length) {
|
||||
if (ulIsBigEndian) {
|
||||
return;
|
||||
} else {
|
||||
for (int i = 0; i < length; i++) {
|
||||
ulEndianSwap(x++);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void ulEndianBigArrayFloat(float *x, int length) {
|
||||
if (ulIsBigEndian) {
|
||||
return;
|
||||
} else {
|
||||
for (int i = 0; i < length; i++) {
|
||||
ulEndianSwap(x++);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline unsigned short ulEndianBig16(unsigned short x) {
|
||||
if (ulIsBigEndian) {
|
||||
return x;
|
||||
} else {
|
||||
ulEndianSwap(&x);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
inline unsigned int ulEndianBig32(unsigned int x) {
|
||||
if (ulIsBigEndian) {
|
||||
return x;
|
||||
} else {
|
||||
ulEndianSwap(&x);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
inline float ulEndianBigFloat(float x) {
|
||||
if (ulIsBigEndian) {
|
||||
return x;
|
||||
} else {
|
||||
ulEndianSwap(&x);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
inline unsigned short ulEndianReadLittle16(FILE *f) {
|
||||
unsigned short x;
|
||||
fread(&x, 2, 1, f);
|
||||
return ulEndianLittle16(x);
|
||||
}
|
||||
|
||||
inline unsigned int ulEndianReadLittle32(FILE *f) {
|
||||
unsigned int x;
|
||||
fread(&x, 4, 1, f);
|
||||
return ulEndianLittle32(x);
|
||||
}
|
||||
|
||||
inline float ulEndianReadLittleFloat(FILE *f) {
|
||||
float x;
|
||||
fread(&x, 4, 1, f);
|
||||
return ulEndianLittleFloat(x);
|
||||
}
|
||||
|
||||
inline unsigned short ulEndianReadBig16(FILE *f) {
|
||||
unsigned short x;
|
||||
fread(&x, 2, 1, f);
|
||||
return ulEndianBig16(x);
|
||||
}
|
||||
|
||||
inline unsigned int ulEndianReadBig32(FILE *f) {
|
||||
unsigned int x;
|
||||
fread(&x, 4, 1, f);
|
||||
return ulEndianBig32(x);
|
||||
}
|
||||
|
||||
inline float ulEndianReadBigFloat(FILE *f) {
|
||||
float x;
|
||||
fread(&x, 4, 1, f);
|
||||
return ulEndianBigFloat(x);
|
||||
}
|
||||
|
||||
inline size_t ulEndianWriteLittle16(FILE *f, unsigned short x) {
|
||||
x = ulEndianLittle16(x);
|
||||
return fwrite( &x, 2, 1, f );
|
||||
}
|
||||
|
||||
inline size_t ulEndianWriteLittle32(FILE *f, unsigned int x) {
|
||||
x = ulEndianLittle32(x);
|
||||
return fwrite( &x, 4, 1, f );
|
||||
}
|
||||
|
||||
inline size_t ulEndianWriteLittleFloat(FILE *f, float x) {
|
||||
x = ulEndianLittleFloat(x);
|
||||
return fwrite( &x, 4, 1, f );
|
||||
}
|
||||
|
||||
inline size_t ulEndianWriteBig16(FILE *f, unsigned short x) {
|
||||
x = ulEndianBig16(x);
|
||||
return fwrite( &x, 2, 1, f );
|
||||
}
|
||||
|
||||
inline size_t ulEndianWriteBig32(FILE *f, unsigned int x) {
|
||||
x = ulEndianBig32(x);
|
||||
return fwrite( &x, 4, 1, f );
|
||||
}
|
||||
|
||||
inline size_t ulEndianWriteBigFloat(FILE *f, float x) {
|
||||
x = ulEndianBigFloat(x);
|
||||
return fwrite( &x, 4, 1, f );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Windoze/BEOS code based on contribution from Sean L. Palmer
|
||||
*/
|
||||
|
||||
|
||||
#ifdef UL_WIN32
|
||||
|
||||
class ulDynamicLibrary
|
||||
{
|
||||
HMODULE handle ;
|
||||
|
||||
public:
|
||||
|
||||
ulDynamicLibrary ( const char *libname )
|
||||
{
|
||||
char dllname[1024];
|
||||
strcpy ( dllname, libname ) ;
|
||||
strcat ( dllname, ".dll" ) ;
|
||||
handle = (HMODULE) LoadLibrary ( dllname ) ;
|
||||
}
|
||||
|
||||
void *getFuncAddress ( const char *funcname )
|
||||
{
|
||||
return (void *) GetProcAddress ( handle, funcname ) ; //lint !e611
|
||||
}
|
||||
|
||||
~ulDynamicLibrary ()
|
||||
{
|
||||
if ( handle != NULL )
|
||||
FreeLibrary ( handle ) ;
|
||||
}
|
||||
} ;
|
||||
|
||||
#elif defined (UL_MACINTOSH)
|
||||
|
||||
class ulDynamicLibrary
|
||||
{
|
||||
CFragConnectionID connection;
|
||||
OSStatus error;
|
||||
|
||||
public:
|
||||
|
||||
ulDynamicLibrary ( const char *libname )
|
||||
{
|
||||
Str63 pstr;
|
||||
int sz;
|
||||
|
||||
sz = strlen (libname);
|
||||
|
||||
if (sz < 64) {
|
||||
|
||||
pstr[0] = sz;
|
||||
memcpy (pstr+1, libname, sz);
|
||||
|
||||
error = GetSharedLibrary (pstr, kPowerPCCFragArch, kReferenceCFrag,
|
||||
&connection, NULL, NULL);
|
||||
}
|
||||
else
|
||||
error = 1;
|
||||
}
|
||||
|
||||
~ulDynamicLibrary ()
|
||||
{
|
||||
if ( ! error )
|
||||
CloseConnection (&connection);
|
||||
}
|
||||
|
||||
void* getFuncAddress ( const char *funcname )
|
||||
{
|
||||
if ( ! error ) {
|
||||
|
||||
char* addr;
|
||||
Str255 sym;
|
||||
int sz;
|
||||
|
||||
sz = strlen (funcname);
|
||||
if (sz < 256) {
|
||||
|
||||
sym[0] = sz;
|
||||
memcpy (sym+1, funcname, sz);
|
||||
|
||||
error = FindSymbol (connection, sym, &addr, 0);
|
||||
if ( ! error )
|
||||
return addr;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
};
|
||||
|
||||
#elif defined (UL_MAC_OSX)
|
||||
|
||||
|
||||
class ulDynamicLibrary
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
ulDynamicLibrary ( const char *libname )
|
||||
{
|
||||
}
|
||||
|
||||
~ulDynamicLibrary ()
|
||||
{
|
||||
}
|
||||
|
||||
void* getFuncAddress ( const char *funcname )
|
||||
{
|
||||
ulSetError ( UL_WARNING, "ulDynamicLibrary unsuppored on Mac OS X" );
|
||||
return NULL;
|
||||
}
|
||||
};
|
||||
|
||||
#elif defined (__BEOS__)
|
||||
|
||||
class ulDynamicLibrary
|
||||
{
|
||||
image_id *handle ;
|
||||
|
||||
public:
|
||||
|
||||
ulDynamicLibrary ( const char *libname )
|
||||
{
|
||||
char addonname[1024] ;
|
||||
strcpy ( addonname, libname ) ;
|
||||
strcat ( addonname, ".so" ) ;
|
||||
handle = new image_id ;
|
||||
|
||||
*handle = load_add_on ( addonname ) ;
|
||||
|
||||
if ( *handle == B_ERROR )
|
||||
{
|
||||
delete handle ;
|
||||
handle = NULL ;
|
||||
}
|
||||
}
|
||||
|
||||
void *getFuncAddress ( const char *funcname )
|
||||
{
|
||||
void *sym = NULL ;
|
||||
|
||||
if ( handle &&
|
||||
get_image_symbol ( handle, "funcname",
|
||||
B_SYMBOL_TYPE_TEXT, &sym ) == B_NO_ERROR )
|
||||
return sym ;
|
||||
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
~ulDynamicLibrary ()
|
||||
{
|
||||
if ( handle != NULL )
|
||||
unload_add_on ( handle ) ;
|
||||
|
||||
delete handle ;
|
||||
}
|
||||
} ;
|
||||
|
||||
# else
|
||||
|
||||
/*
|
||||
Linux/UNIX
|
||||
*/
|
||||
|
||||
class ulDynamicLibrary
|
||||
{
|
||||
void *handle ;
|
||||
|
||||
public:
|
||||
|
||||
ulDynamicLibrary ( const char *libname )
|
||||
{
|
||||
char dsoname [ 1024 ] ;
|
||||
strcpy ( dsoname, libname ) ;
|
||||
strcat ( dsoname, ".so" ) ;
|
||||
handle = (void *) dlopen ( dsoname, RTLD_NOW | RTLD_GLOBAL ) ;
|
||||
|
||||
if ( handle == NULL )
|
||||
ulSetError ( UL_WARNING, "ulDynamicLibrary: %s\n", dlerror() ) ;
|
||||
}
|
||||
|
||||
void *getFuncAddress ( const char *funcname )
|
||||
{
|
||||
return (handle==NULL) ? NULL : dlsym ( handle, funcname ) ;
|
||||
}
|
||||
|
||||
~ulDynamicLibrary ()
|
||||
{
|
||||
if ( handle != NULL )
|
||||
dlclose ( handle ) ;
|
||||
}
|
||||
} ;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
class ulList
|
||||
{
|
||||
protected:
|
||||
unsigned int total ; /* The total number of entities in the list */
|
||||
unsigned int limit ; /* The current limit on number of entities */
|
||||
unsigned int next ; /* The next entity when we are doing getNext ops */
|
||||
|
||||
void **entity_list ; /* The list. */
|
||||
|
||||
void sizeChk (void) ;
|
||||
|
||||
public:
|
||||
|
||||
ulList ( int init_max = 1 ) ;
|
||||
virtual ~ulList (void) ;
|
||||
|
||||
void *getEntity ( unsigned int n )
|
||||
{
|
||||
next = n + 1 ;
|
||||
return ( n >= total ) ? (void *) NULL : entity_list [ n ] ;
|
||||
}
|
||||
|
||||
virtual void addEntity ( void *entity ) ;
|
||||
virtual void addEntityBefore ( int n, void *entity ) ;
|
||||
virtual void removeEntity ( unsigned int n ) ;
|
||||
|
||||
void removeAllEntities () ;
|
||||
|
||||
void removeEntity ( void *entity )
|
||||
{
|
||||
removeEntity ( searchForEntity ( entity ) ) ;
|
||||
}
|
||||
|
||||
virtual void replaceEntity ( unsigned int n, void *new_entity ) ;
|
||||
|
||||
void replaceEntity ( void *old_entity, void *new_entity )
|
||||
{
|
||||
replaceEntity ( searchForEntity ( old_entity ), new_entity ) ;
|
||||
}
|
||||
|
||||
void *getNextEntity (void) { return getEntity ( next ) ; }
|
||||
|
||||
int getNumEntities (void) const { return total ; }
|
||||
int searchForEntity ( void *entity ) const ;
|
||||
} ;
|
||||
|
||||
|
||||
typedef bool (*ulIterateFunc)( const void *data, void *user_data ) ;
|
||||
typedef int (*ulCompareFunc)( const void *data1, const void *data2 ) ;
|
||||
|
||||
/*
|
||||
Linked list.
|
||||
*/
|
||||
|
||||
class ulListNode ;
|
||||
|
||||
class ulLinkedList
|
||||
{
|
||||
protected:
|
||||
|
||||
ulListNode *head ;
|
||||
ulListNode *tail ;
|
||||
|
||||
int nnodes ;
|
||||
bool sorted ;
|
||||
|
||||
void unlinkNode ( ulListNode *prev, ulListNode *node ) ;
|
||||
|
||||
bool isValidPosition ( int pos ) const
|
||||
{
|
||||
if ( ( pos < 0 ) || ( pos >= nnodes ) )
|
||||
{
|
||||
ulSetError ( UL_WARNING, "ulLinkedList: Invalid 'pos' %u", pos ) ;
|
||||
return false ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
ulLinkedList ()
|
||||
{
|
||||
head = tail = NULL ;
|
||||
nnodes = 0 ;
|
||||
sorted = true ;
|
||||
}
|
||||
|
||||
~ulLinkedList () { empty () ; }
|
||||
|
||||
int getNumNodes ( void ) const { return nnodes ; }
|
||||
bool isSorted ( void ) const { return sorted ; }
|
||||
|
||||
int getNodePosition ( void *data ) const ;
|
||||
|
||||
void insertNode ( void *data, int pos ) ;
|
||||
void prependNode ( void *data ) { insertNode ( data, 0 ) ; }
|
||||
void appendNode ( void *data ) ;
|
||||
|
||||
int insertSorted ( void *data, ulCompareFunc comparefn ) ;
|
||||
|
||||
void removeNode ( void *data ) ;
|
||||
void * removeNode ( int pos ) ;
|
||||
|
||||
void * getNodeData ( int pos ) const ;
|
||||
|
||||
void * forEach ( ulIterateFunc fn, void *user_data = NULL ) const ;
|
||||
|
||||
void empty ( ulIterateFunc destroyfn = NULL, void *user_data = NULL ) ;
|
||||
} ;
|
||||
|
||||
|
||||
extern char *ulStrDup ( const char *s ) ;
|
||||
extern int ulStrNEqual ( const char *s1, const char *s2, int len );
|
||||
extern int ulStrEqual ( const char *s1, const char *s2 );
|
||||
|
||||
//lint -restore
|
||||
|
||||
#endif
|
||||
|
||||
420
include/plib/ulRTTI.h
Normal file
420
include/plib/ulRTTI.h
Normal file
@@ -0,0 +1,420 @@
|
||||
/*
|
||||
PLIB - A Suite of Portable Game Libraries
|
||||
Copyright (C) 1998,2002 Steve Baker
|
||||
|
||||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information visit http://plib.sourceforge.net */
|
||||
|
||||
|
||||
/*
|
||||
Originally written by: Alexandru C. Telea <alext@win.tue.nl>
|
||||
*/
|
||||
|
||||
/*
|
||||
This file provides support for RTTI and generalized (virtual-base to derived
|
||||
and separate hierarchy branches) casting. There is also support for RT obj
|
||||
creation from type names.
|
||||
|
||||
In order to enable these features for a class, two things should be done:
|
||||
|
||||
1) insert the text UL_TYPE_DATA (without ';') in the class-decl.
|
||||
2) in the .C file where the class's implementation resides, insert the
|
||||
following (without';'):
|
||||
|
||||
UL_RTTI_DEF(classname)
|
||||
if the class has no bases with RTTI
|
||||
|
||||
UL_RTTI_DEFn(classname,b1,...bn)
|
||||
if the class has bases b1,...bn with RTTI
|
||||
|
||||
Use UL_RTTI_DEF_INST instead of UL_RTTI_DEF if you want to enable RT
|
||||
obj creation for classname. You should provide then a public default
|
||||
ctor.
|
||||
|
||||
RTTI is used via a class called ulRTTItypeid. A typeid describes a type of a
|
||||
class. [..] They should provide all necessary support for any kind of
|
||||
RTTI/casting [..].
|
||||
|
||||
[..]
|
||||
|
||||
REMARK: There are two classes related to RTTI: ulRTTItypeid and
|
||||
======= ulRTTITypeinfo. A ulRTTItypeid is, as it says, an 'id for a
|
||||
type'. It actually wraps a ulRTTITypeinfo*, where a
|
||||
ulRTTITypeinfo contains the actual encoding of a class type.
|
||||
You can freely create/copy/destroy/manipulate ulRTTItypeid's,
|
||||
but you should NEVER deal directly with ulRTTITypeinfo. A
|
||||
ulRTTITypeinfo should actually be created ONLY by the
|
||||
UL_TYPE_DATA macros, as part of a class definition, since the
|
||||
ulRTTITypeinfo encodes a type info for an EXISTING class [..].
|
||||
All type-related stuff should be therefore handled via
|
||||
ulRTTItypeid's.
|
||||
*/
|
||||
|
||||
#ifndef _UL_RTTI_H_
|
||||
#define _UL_RTTI_H_
|
||||
|
||||
#include <string.h>
|
||||
#include "ul.h"
|
||||
|
||||
|
||||
class ulRTTITypeinfo
|
||||
/* Implementation of type-related info */
|
||||
{
|
||||
private:
|
||||
|
||||
char *n ; /* type name */
|
||||
|
||||
/*
|
||||
base types (NULL-ended array of ulRTTITypeinfo's for this's direct bases)
|
||||
*/
|
||||
const ulRTTITypeinfo** b ;
|
||||
|
||||
int ns ; /* #subtypes of this type */
|
||||
const ulRTTITypeinfo **subtypes ; /* types derived from this type */
|
||||
|
||||
/* convenience type info for a 'null' type */
|
||||
static const ulRTTITypeinfo null_type ;
|
||||
|
||||
void* (*new_obj)() ; /* func to create a new obj of this type */
|
||||
void* (*cast)(int,void*) ; /*
|
||||
func to cast an obj of this type to ith
|
||||
baseclass of it or to itself
|
||||
*/
|
||||
|
||||
/* adds a subtype to this's subtypes[] */
|
||||
void add_subtype ( const ulRTTITypeinfo * ) ;
|
||||
|
||||
/* dels a subtype from this's subtypes[] */
|
||||
void del_subtype ( const ulRTTITypeinfo* ) ;
|
||||
|
||||
friend class ulRTTItypeid ; /* for null_type */
|
||||
|
||||
public:
|
||||
|
||||
ulRTTITypeinfo ( const char* name, const ulRTTITypeinfo* bb[],
|
||||
void* (*)(int,void*),void* (*)() ) ;
|
||||
~ulRTTITypeinfo () ;
|
||||
|
||||
/* Returns name of this ulRTTITypeinfo */
|
||||
const char* getname () const { return n ; }
|
||||
|
||||
/* Compares 2 ulRTTITypeinfo objs */
|
||||
bool same ( const ulRTTITypeinfo *p ) const
|
||||
{
|
||||
/*
|
||||
First, try to see if it's the same 'physical' ulRTTITypeinfo (which
|
||||
should be the case, since we create them per-class and not per-obj).
|
||||
*/
|
||||
return ( this == p ) || !strcmp ( n, p->n ) ;
|
||||
}
|
||||
|
||||
/* true if the arg can be cast to this, else false */
|
||||
bool can_cast ( const ulRTTITypeinfo *p ) const
|
||||
{
|
||||
return same ( p ) || p->has_base ( this ) ;
|
||||
}
|
||||
|
||||
/* true if this has the arg as some base, else false */
|
||||
bool has_base ( const ulRTTITypeinfo *p ) const
|
||||
{
|
||||
for ( int i = 0 ; b[i] != NULL ; i++ ) /* for all bases of this... */
|
||||
/* match found, return 1 or no match, search deeper */
|
||||
if ( p->same ( b[i] ) || b[i]->has_base ( p ) ) return true ;
|
||||
return false ; /* no match at all, return false */
|
||||
}
|
||||
|
||||
/* get i-th subclass of this, if any, else NULL */
|
||||
const ulRTTITypeinfo * subclass ( int i = 0 ) const
|
||||
{
|
||||
return ( i >= 0 && i < ns ) ? subtypes[i] : NULL ;
|
||||
}
|
||||
|
||||
int num_subclasses () const { return ns ; } /* get # subclasses of this */
|
||||
|
||||
/*
|
||||
search for a subclass named char*, create obj of it and return it cast to
|
||||
the ulRTTITypeinfo* type, which is either this or a direct base of this.
|
||||
*/
|
||||
void * create ( const ulRTTITypeinfo *, const char * ) const ;
|
||||
|
||||
/* Returns true if this type has a default ctor, else false */
|
||||
bool can_create () const { return new_obj != NULL ; }
|
||||
} ;
|
||||
|
||||
|
||||
class ulRTTItypeid
|
||||
/* Main class for RTTI interface */
|
||||
{
|
||||
protected:
|
||||
|
||||
/* ulRTTItypeid implementation (the only data-member) */
|
||||
const ulRTTITypeinfo* id ;
|
||||
|
||||
public:
|
||||
|
||||
/* Not for application use ! */
|
||||
const ulRTTITypeinfo* get_info () const { return id ; }
|
||||
|
||||
ulRTTItypeid ( const ulRTTITypeinfo* p ) : id ( p ) { }
|
||||
ulRTTItypeid () : id ( &ulRTTITypeinfo::null_type ) { }
|
||||
|
||||
/* Compares 2 ulRTTItypeid objs */
|
||||
bool isSame ( ulRTTItypeid i ) const { return id->same ( i.id ) ; }
|
||||
|
||||
/* true if the arg can be cast to this, else false */
|
||||
bool canCast ( ulRTTItypeid i ) const { return id->can_cast ( i.id ) ; }
|
||||
|
||||
const char * getName () const { return id->getname () ; }
|
||||
|
||||
/* Return # subclasses of this */
|
||||
int getNumSubclasses () const { return id->num_subclasses () ; }
|
||||
|
||||
/* Return ith subclass of this */
|
||||
ulRTTItypeid getSubclass ( int i ) const { return id->subclass ( i ) ; }
|
||||
|
||||
/* Return # baseclasses of this */
|
||||
int getNumBaseclasses () const
|
||||
{
|
||||
int i ; for ( i = 0 ; id->b[i] != NULL ; i++ ) ;
|
||||
return i ;
|
||||
}
|
||||
|
||||
/* Return ith baseclass of this */
|
||||
ulRTTItypeid getBaseclass ( int i ) const { return id->b[i] ; }
|
||||
|
||||
/*
|
||||
Tries to create an instance of a subclass of this having of type given
|
||||
by the ulRTTItypeid arg. If ok, it returns it casted to the class-type of
|
||||
this and then to void*
|
||||
*/
|
||||
void * create ( ulRTTItypeid t ) const
|
||||
{
|
||||
return id->create ( id, t.getName () ) ;
|
||||
}
|
||||
|
||||
/* Returns true if this type is instantiable, else false */
|
||||
bool canCreate () const { return id->can_create () ; }
|
||||
} ;
|
||||
|
||||
|
||||
class ulRTTIdyntypeid : public ulRTTItypeid
|
||||
/*
|
||||
Class for dynamic type creation from user strings. Useful for creating
|
||||
typeids at RT for comparison purposes.
|
||||
*/
|
||||
{
|
||||
private:
|
||||
|
||||
static const ulRTTITypeinfo *a[] ;
|
||||
|
||||
public:
|
||||
|
||||
ulRTTIdyntypeid ( const char *c ) :
|
||||
/* create a dummy ulRTTITypeinfo */
|
||||
ulRTTItypeid ( new ulRTTITypeinfo ( c, a, NULL, NULL ) ) { }
|
||||
|
||||
~ulRTTIdyntypeid () { delete id ; /* delete the dummy ulRTTITypeinfo */ }
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
Macros
|
||||
*/
|
||||
|
||||
/*
|
||||
'ulRTTItypeid'
|
||||
UL_STATIC_TYPE_INFO(T) T=RTTI-class name.
|
||||
Returns a ulRTTItypeid with T's type. If T
|
||||
hasn't RTTI, a compile-time error occurs.
|
||||
*/
|
||||
|
||||
#define UL_STATIC_TYPE_INFO(T) T::RTTI_sinfo()
|
||||
|
||||
|
||||
/*
|
||||
'T*'
|
||||
UL_PTR_CAST(T,p) T=RTTI-class, p=RTTI-class ptr.
|
||||
Returns p cast to the type T as a T*, if cast is
|
||||
possible, else returns NULL. If *p or T have no RTTI,
|
||||
a compile-time error occurs. Note that p can point to
|
||||
virtual base classes. Casting between separat branches
|
||||
of a class hierarchy is also supported, as long as all
|
||||
classes have RTTI. Therefore UL_PTR_CAST is a fully
|
||||
general and safe operator. If p==NULL, the operator
|
||||
returns NULL.
|
||||
*/
|
||||
|
||||
#define UL_PTR_CAST(T,p) ((p != NULL)? (T*)((p)->RTTI_cast(UL_STATIC_TYPE_INFO(T))) : NULL)
|
||||
|
||||
|
||||
/* 'T*'
|
||||
UL_TYPE_NEW(T,t) T=RTTI-class, t=ulRTTItypeid
|
||||
Returns a new object of type t cast to the type T as
|
||||
a T*. t must represent a type identical to or derived
|
||||
from T. If t is not a type derived from T or not an
|
||||
instantiable type having a default constructor, NULL is
|
||||
returned. */
|
||||
|
||||
#define UL_TYPE_NEW(T,t) ((T*)t.create(T))
|
||||
|
||||
|
||||
|
||||
/*
|
||||
Definition of TYPE_DATA for a RTTI-class: introduces one static
|
||||
ulRTTITypeinfo data-member and a couple of virtuals.
|
||||
*/
|
||||
|
||||
#define UL_TYPE_DATA \
|
||||
protected: \
|
||||
static const ulRTTITypeinfo RTTI_obj; \
|
||||
static void* RTTI_scast(int,void*); \
|
||||
static void* RTTI_new(); \
|
||||
virtual ulRTTItypeid RTTI_vinfo() const { return &RTTI_obj; }\
|
||||
public: \
|
||||
static ulRTTItypeid RTTI_sinfo() { return &RTTI_obj; }\
|
||||
virtual void* RTTI_cast(ulRTTItypeid);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
Definition of auxiliary data-structs supporting RTTI for a class: defines
|
||||
the static ulRTTITypeinfo object of that class and its associated virtuals.
|
||||
*/
|
||||
|
||||
/* Auxiliary definition of the construction method: */
|
||||
#define UL_RTTI_NEW(cls) void* cls::RTTI_new() { return new cls; } \
|
||||
const ulRTTITypeinfo cls::RTTI_obj(#cls,RTTI_base_ ## cls,cls::RTTI_scast,cls::RTTI_new);
|
||||
|
||||
#define UL_RTTI_NO_NEW(cls) const ulRTTITypeinfo cls::RTTI_obj(#cls,RTTI_base_ ## cls,cls::RTTI_scast,NULL);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
Top-level macros:
|
||||
*/
|
||||
|
||||
#define UL_RTTI_DEF_BASE(cls) \
|
||||
static const ulRTTITypeinfo* RTTI_base_ ## cls [] = { NULL }; \
|
||||
void* cls::RTTI_cast(ulRTTItypeid t) \
|
||||
{ \
|
||||
if (t.isSame(&RTTI_obj)) return this; \
|
||||
return NULL; \
|
||||
} \
|
||||
void* cls::RTTI_scast(int i,void* p) \
|
||||
{ cls* ptr = (cls*)p; return ptr; }
|
||||
|
||||
|
||||
#define UL_RTTI_DEF1_BASE(cls,b1) \
|
||||
static const ulRTTITypeinfo* RTTI_base_ ## cls [] = \
|
||||
{ UL_STATIC_TYPE_INFO(b1).get_info(), NULL }; \
|
||||
void* cls::RTTI_cast(ulRTTItypeid t) \
|
||||
{ \
|
||||
if (t.isSame(&RTTI_obj)) return this; \
|
||||
void* ptr; \
|
||||
if ((ptr=b1::RTTI_cast(t))) return ptr; \
|
||||
return NULL; \
|
||||
} \
|
||||
void* cls::RTTI_scast(int i,void* p) \
|
||||
{ cls* ptr = (cls*)p; \
|
||||
switch(i) \
|
||||
{ case 0: return (b1*)ptr; } \
|
||||
return ptr; \
|
||||
}
|
||||
|
||||
|
||||
#define UL_RTTI_DEF2_BASE(cls,b1,b2) \
|
||||
static const ulRTTITypeinfo* RTTI_base_ ## cls [] = \
|
||||
{ UL_STATIC_TYPE_INFO(b1).get_info(), \
|
||||
UL_STATIC_TYPE_INFO(b2).get_info(), NULL }; \
|
||||
void* cls::RTTI_cast(ulRTTItypeid t) \
|
||||
{ \
|
||||
if (t.isSame(&RTTI_obj)) return this; \
|
||||
void* ptr; \
|
||||
if ((ptr=b1::RTTI_cast(t))) return ptr; \
|
||||
if ((ptr=b2::RTTI_cast(t))) return ptr; \
|
||||
return NULL; \
|
||||
} \
|
||||
void* cls::RTTI_scast(int i,void* p) \
|
||||
{ cls* ptr = (cls*)p; \
|
||||
switch(i) \
|
||||
{ case 0: return (b1*)ptr; \
|
||||
case 1: return (b2*)ptr; \
|
||||
} \
|
||||
return ptr; \
|
||||
}
|
||||
|
||||
#define UL_RTTI_DEF3_BASE(cls,b1,b2,b3) \
|
||||
static const ulRTTITypeinfo* RTTI_base_ ## cls [] = \
|
||||
{ UL_STATIC_TYPE_INFO(b1).get_info(), \
|
||||
UL_STATIC_TYPE_INFO(b2).get_info(), \
|
||||
UL_STATIC_TYPE_INFO(b3).get_info(), NULL }; \
|
||||
void* cls::RTTI_cast(ulRTTItypeid t) \
|
||||
{ \
|
||||
if (t.isSame(&RTTI_obj)) return this; \
|
||||
void* ptr; \
|
||||
if ((ptr=b1::RTTI_cast(t))) return ptr; \
|
||||
if ((ptr=b2::RTTI_cast(t))) return ptr; \
|
||||
if ((ptr=b3::RTTI_cast(t))) return ptr; \
|
||||
return NULL; \
|
||||
} \
|
||||
void* cls::RTTI_scast(int i,void* p) \
|
||||
{ cls* ptr = (cls*)p; \
|
||||
switch(i) \
|
||||
{ case 0: return (b1*)ptr; \
|
||||
case 1: return (b2*)ptr; \
|
||||
case 2: return (b3*)ptr; \
|
||||
} \
|
||||
return ptr; \
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define UL_RTTI_DEF_INST(cls) \
|
||||
UL_RTTI_DEF_BASE(cls) \
|
||||
UL_RTTI_NEW(cls)
|
||||
|
||||
#define UL_RTTI_DEF(cls) \
|
||||
UL_RTTI_DEF_BASE(cls) \
|
||||
UL_RTTI_NO_NEW(cls)
|
||||
|
||||
#define UL_RTTI_DEF1_INST(cls,b1) \
|
||||
UL_RTTI_DEF1_BASE(cls,b1) \
|
||||
UL_RTTI_NEW(cls)
|
||||
|
||||
#define UL_RTTI_DEF1(cls,b1) \
|
||||
UL_RTTI_DEF1_BASE(cls,b1) \
|
||||
UL_RTTI_NO_NEW(cls)
|
||||
|
||||
#define UL_RTTI_DEF2_INST(cls,b1,b2) \
|
||||
UL_RTTI_DEF2_BASE(cls,b1,b2) \
|
||||
UL_RTTI_NEW(cls)
|
||||
|
||||
#define UL_RTTI_DEF2(cls,b1,b2) \
|
||||
UL_RTTI_DEF2_BASE(cls,b1,b2) \
|
||||
UL_RTTI_NO_NEW(cls)
|
||||
|
||||
#define UL_RTTI_DEF3_INST(cls,b1,b2,b3) \
|
||||
UL_RTTI_DEF3_BASE(cls,b1,b2,b3) \
|
||||
UL_RTTI_NEW(cls)
|
||||
|
||||
#define UL_RTTI_DEF3(cls,b1,b2,b3) \
|
||||
UL_RTTI_DEF3_BASE(cls,b1,b2,b3) \
|
||||
UL_RTTI_NO_NEW(cls)
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
BIN
lib/libfreetype.a
Normal file
BIN
lib/libfreetype.a
Normal file
Binary file not shown.
41
lib/libfreetype.la
Executable file
41
lib/libfreetype.la
Executable file
@@ -0,0 +1,41 @@
|
||||
# libfreetype.la - a libtool library file
|
||||
# Generated by libtool (GNU libtool) 2.4.2
|
||||
#
|
||||
# Please DO NOT delete this file!
|
||||
# It is necessary for linking the library.
|
||||
|
||||
# The name that we can dlopen(3).
|
||||
dlname=''
|
||||
|
||||
# Names of this library.
|
||||
library_names=''
|
||||
|
||||
# The name of the static archive.
|
||||
old_library='libfreetype.a'
|
||||
|
||||
# Linker flags that can not go in dependency_libs.
|
||||
inherited_linker_flags=' '
|
||||
|
||||
# Libraries that this one depends upon.
|
||||
dependency_libs=' -lz'
|
||||
|
||||
# Names of additional weak libraries provided by this library
|
||||
weak_library_names=''
|
||||
|
||||
# Version information for libfreetype.
|
||||
current=16
|
||||
age=10
|
||||
revision=1
|
||||
|
||||
# Is this an already installed library?
|
||||
installed=yes
|
||||
|
||||
# Should we warn about portability when linking against -modules?
|
||||
shouldnotlink=no
|
||||
|
||||
# Files to dlopen/dlpreopen
|
||||
dlopen=''
|
||||
dlpreopen=''
|
||||
|
||||
# Directory that this library needs to be installed in:
|
||||
libdir='/Users/jenkins/jenkins-root/workspace/Mac-FreeType/dist/lib'
|
||||
BIN
lib/libplibfnt.a
Normal file
BIN
lib/libplibfnt.a
Normal file
Binary file not shown.
BIN
lib/libplibjs.a
Normal file
BIN
lib/libplibjs.a
Normal file
Binary file not shown.
BIN
lib/libplibnet.a
Normal file
BIN
lib/libplibnet.a
Normal file
Binary file not shown.
BIN
lib/libplibpu.a
Normal file
BIN
lib/libplibpu.a
Normal file
Binary file not shown.
BIN
lib/libplibpuaux.a
Normal file
BIN
lib/libplibpuaux.a
Normal file
Binary file not shown.
BIN
lib/libplibsg.a
Normal file
BIN
lib/libplibsg.a
Normal file
Binary file not shown.
BIN
lib/libplibul.a
Normal file
BIN
lib/libplibul.a
Normal file
Binary file not shown.
Reference in New Issue
Block a user