Holy fucking shit I don't want to work on this. Sibly, you son of a ...
This commit is contained in:
@@ -0,0 +1,594 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "bbsys.h"
|
||||
|
||||
//how many strings allocated
|
||||
static int stringCnt;
|
||||
|
||||
//how many objects new'd but not deleted
|
||||
static int objCnt;
|
||||
|
||||
//how many objects deleted but not released
|
||||
static int unrelObjCnt;
|
||||
|
||||
//how many objects to alloc per block
|
||||
static const int OBJ_NEW_INC=512;
|
||||
|
||||
//how many strings to alloc per block
|
||||
static const int STR_NEW_INC=512;
|
||||
|
||||
//current data ptr
|
||||
static BBData *dataPtr;
|
||||
|
||||
//chunks of mem - WHAT THE FUCK WAS I ON?!?!?!?
|
||||
//static list<char*> memBlks;
|
||||
|
||||
//strings
|
||||
static BBStr usedStrs,freeStrs;
|
||||
|
||||
//object handle number
|
||||
static int next_handle;
|
||||
|
||||
//object<->handle maps
|
||||
static map<int,BBObj*> handle_map;
|
||||
static map<BBObj*,int> object_map;
|
||||
|
||||
static BBType _bbIntType( BBTYPE_INT );
|
||||
static BBType _bbFltType( BBTYPE_FLT );
|
||||
static BBType _bbStrType( BBTYPE_STR );
|
||||
static BBType _bbCStrType( BBTYPE_CSTR );
|
||||
|
||||
static void *bbMalloc( int size ){
|
||||
return malloc(size);
|
||||
/*
|
||||
char *c=d_new char[ size ];
|
||||
memBlks.push_back( c );
|
||||
return c;
|
||||
*/
|
||||
}
|
||||
|
||||
static void bbFree( void *q ){
|
||||
free(q);
|
||||
/*
|
||||
if( !q ) return;
|
||||
char *c=(char*)q;
|
||||
memBlks.remove( c );
|
||||
delete [] c;
|
||||
*/
|
||||
}
|
||||
|
||||
static void removeStr( BBStr *str ){
|
||||
str->next->prev=str->prev;
|
||||
str->prev->next=str->next;
|
||||
}
|
||||
|
||||
static void insertStr( BBStr *str,BBStr *next ){
|
||||
str->next=next;
|
||||
str->prev=next->prev;
|
||||
str->prev->next=str;
|
||||
next->prev=str;
|
||||
}
|
||||
|
||||
void *BBStr::operator new( size_t size ){
|
||||
if( freeStrs.next==&freeStrs ){
|
||||
BBStr *t=(BBStr*)bbMalloc( sizeof(BBStr)*STR_NEW_INC );
|
||||
for( int k=0;k<STR_NEW_INC;++k ) insertStr( t++,&freeStrs );
|
||||
}
|
||||
BBStr *t=freeStrs.next;
|
||||
removeStr( t );insertStr( t,&usedStrs );
|
||||
return t;
|
||||
}
|
||||
|
||||
void BBStr::operator delete( void *q ){
|
||||
if( !q ) return;
|
||||
BBStr *t=(BBStr*)q;
|
||||
removeStr( t );insertStr( t,&freeStrs );
|
||||
}
|
||||
|
||||
BBStr::BBStr(){
|
||||
++stringCnt;
|
||||
}
|
||||
|
||||
BBStr::BBStr( const char *s ):string(s){
|
||||
++stringCnt;
|
||||
}
|
||||
|
||||
BBStr::BBStr( const char *s,int n ):string(s,n){
|
||||
++stringCnt;
|
||||
}
|
||||
|
||||
BBStr::BBStr( const BBStr &s ):string(s){
|
||||
++stringCnt;
|
||||
}
|
||||
|
||||
BBStr::BBStr( const string &s ):string(s){
|
||||
++stringCnt;
|
||||
}
|
||||
|
||||
BBStr &BBStr::operator=( const char *s ){
|
||||
string::operator=( s );return *this;
|
||||
}
|
||||
|
||||
BBStr &BBStr::operator=( const BBStr &s ){
|
||||
string::operator=( s );return *this;
|
||||
}
|
||||
|
||||
BBStr &BBStr::operator=( const string &s ){
|
||||
string::operator=( s );return *this;
|
||||
}
|
||||
|
||||
BBStr::~BBStr(){
|
||||
--stringCnt;
|
||||
}
|
||||
|
||||
BBStr *_bbStrLoad( BBStr **var ){
|
||||
return *var ? d_new BBStr( **var ) : d_new BBStr();
|
||||
}
|
||||
|
||||
void _bbStrRelease( BBStr *str ){
|
||||
delete str;
|
||||
}
|
||||
|
||||
void _bbStrStore( BBStr **var,BBStr *str ){
|
||||
_bbStrRelease( *var );*var=str;
|
||||
}
|
||||
|
||||
BBStr *_bbStrConcat( BBStr *s1,BBStr *s2 ){
|
||||
*s1+=*s2;delete s2;return s1;
|
||||
}
|
||||
|
||||
int _bbStrCompare( BBStr *lhs,BBStr *rhs ){
|
||||
int n=lhs->compare( *rhs );
|
||||
delete lhs;delete rhs;return n;
|
||||
}
|
||||
|
||||
int _bbStrToInt( BBStr *s ){
|
||||
int n=atoi( *s );
|
||||
delete s;return n;
|
||||
}
|
||||
|
||||
BBStr *_bbStrFromInt( int n ){
|
||||
return d_new BBStr( itoa( n ) );
|
||||
}
|
||||
|
||||
float _bbStrToFloat( BBStr *s ){
|
||||
float n=(float)atof( *s );
|
||||
delete s;return n;
|
||||
}
|
||||
|
||||
BBStr *_bbStrFromFloat( float n ){
|
||||
return d_new BBStr( ftoa( n ) );
|
||||
}
|
||||
|
||||
BBStr *_bbStrConst( const char *s ){
|
||||
return d_new BBStr( s );
|
||||
}
|
||||
|
||||
void * _bbVecAlloc( BBVecType *type ){
|
||||
void *vec=bbMalloc( type->size*4 );
|
||||
memset( vec,0,type->size*4 );
|
||||
return vec;
|
||||
}
|
||||
|
||||
void _bbVecFree( void *vec,BBVecType *type ){
|
||||
if( type->elementType->type==BBTYPE_STR ){
|
||||
BBStr **p=(BBStr**)vec;
|
||||
for( int k=0;k<type->size;++p,++k ){
|
||||
if( *p ) _bbStrRelease( *p );
|
||||
}
|
||||
}else if( type->elementType->type==BBTYPE_OBJ ){
|
||||
BBObj **p=(BBObj**)vec;
|
||||
for( int k=0;k<type->size;++p,++k ){
|
||||
if( *p ) _bbObjRelease( *p );
|
||||
}
|
||||
}
|
||||
bbFree( vec );
|
||||
}
|
||||
|
||||
void _bbVecBoundsEx(){
|
||||
ThrowRuntimeException( "Blitz array index out of bounds" );
|
||||
}
|
||||
|
||||
void _bbUndimArray( BBArray *array ){
|
||||
if( void *t=array->data ){
|
||||
if( array->elementType==BBTYPE_STR ){
|
||||
BBStr **p=(BBStr**)t;
|
||||
int size=array->scales[array->dims-1];
|
||||
for( int k=0;k<size;++p,++k ){
|
||||
if( *p ) _bbStrRelease( *p );
|
||||
}
|
||||
}else if( array->elementType==BBTYPE_OBJ ){
|
||||
BBObj **p=(BBObj**)t;
|
||||
int size=array->scales[array->dims-1];
|
||||
for( int k=0;k<size;++p,++k ){
|
||||
if( *p ) _bbObjRelease( *p );
|
||||
}
|
||||
}
|
||||
bbFree( t );
|
||||
array->data=0;
|
||||
}
|
||||
}
|
||||
|
||||
void _bbDimArray( BBArray *array ){
|
||||
int k;
|
||||
for( k=0;k<array->dims;++k ) ++array->scales[k];
|
||||
for( k=1;k<array->dims;++k ){
|
||||
array->scales[k]*=array->scales[k-1];
|
||||
}
|
||||
int size=array->scales[array->dims-1];
|
||||
array->data=bbMalloc( size*4 );
|
||||
memset( array->data,0,size*4 );
|
||||
}
|
||||
|
||||
void _bbArrayBoundsEx(){
|
||||
ThrowRuntimeException( "Array index out of bounds" );
|
||||
}
|
||||
|
||||
static void unlinkObj( BBObj *obj ){
|
||||
obj->next->prev=obj->prev;
|
||||
obj->prev->next=obj->next;
|
||||
}
|
||||
|
||||
static void insertObj( BBObj *obj,BBObj *next ){
|
||||
obj->next=next;
|
||||
obj->prev=next->prev;
|
||||
next->prev->next=obj;
|
||||
next->prev=obj;
|
||||
}
|
||||
|
||||
BBObj *_bbObjNew( BBObjType *type ){
|
||||
if( type->free.next==&type->free ){
|
||||
int obj_size=sizeof(BBObj)+type->fieldCnt*4;
|
||||
BBObj *o=(BBObj*)bbMalloc( obj_size*OBJ_NEW_INC );
|
||||
for( int k=0;k<OBJ_NEW_INC;++k ){
|
||||
insertObj( o,&type->free );
|
||||
o=(BBObj*)( (char*)o+obj_size );
|
||||
}
|
||||
}
|
||||
BBObj *o=type->free.next;
|
||||
unlinkObj( o );
|
||||
o->type=type;
|
||||
o->ref_cnt=1;
|
||||
o->fields=(BBField*)(o+1);
|
||||
for( int k=0;k<type->fieldCnt;++k ){
|
||||
switch( type->fieldTypes[k]->type ){
|
||||
case BBTYPE_VEC:
|
||||
o->fields[k].VEC=_bbVecAlloc( (BBVecType*)type->fieldTypes[k] );
|
||||
break;
|
||||
default:
|
||||
o->fields[k].INT=0;
|
||||
}
|
||||
}
|
||||
insertObj( o,&type->used );
|
||||
++unrelObjCnt;
|
||||
++objCnt;
|
||||
return o;
|
||||
}
|
||||
|
||||
void _bbObjDelete( BBObj *obj ){
|
||||
if( !obj ) return;
|
||||
BBField *fields=obj->fields;
|
||||
if( !fields ) return;
|
||||
BBObjType *type=obj->type;
|
||||
for( int k=0;k<type->fieldCnt;++k ){
|
||||
switch( type->fieldTypes[k]->type ){
|
||||
case BBTYPE_STR:
|
||||
_bbStrRelease( fields[k].STR );
|
||||
break;
|
||||
case BBTYPE_OBJ:
|
||||
_bbObjRelease( fields[k].OBJ );
|
||||
break;
|
||||
case BBTYPE_VEC:
|
||||
_bbVecFree( fields[k].VEC,(BBVecType*)type->fieldTypes[k] );
|
||||
break;
|
||||
}
|
||||
}
|
||||
map<BBObj*,int>::iterator it=object_map.find( obj );
|
||||
if( it!=object_map.end() ){
|
||||
handle_map.erase( it->second );
|
||||
object_map.erase( it );
|
||||
}
|
||||
obj->fields=0;
|
||||
_bbObjRelease( obj );
|
||||
--objCnt;
|
||||
}
|
||||
|
||||
void _bbObjDeleteEach( BBObjType *type ){
|
||||
BBObj *obj=type->used.next;
|
||||
while( obj->type ){
|
||||
BBObj *next=obj->next;
|
||||
if( obj->fields ) _bbObjDelete( obj );
|
||||
obj=next;
|
||||
}
|
||||
}
|
||||
|
||||
extern void bbDebugLog( BBStr *t );
|
||||
extern void bbStop( );
|
||||
|
||||
void _bbObjRelease( BBObj *obj ){
|
||||
if( !obj || --obj->ref_cnt ) return;
|
||||
unlinkObj( obj );
|
||||
insertObj( obj,&obj->type->free );
|
||||
--unrelObjCnt;
|
||||
}
|
||||
|
||||
void _bbObjStore( BBObj **var,BBObj *obj ){
|
||||
if( obj ) ++obj->ref_cnt; //do this first incase of self-assignment
|
||||
_bbObjRelease( *var );
|
||||
*var=obj;
|
||||
}
|
||||
|
||||
int _bbObjCompare( BBObj *o1,BBObj *o2 ){
|
||||
return (o1 ? o1->fields : 0)!=(o2 ? o2->fields : 0);
|
||||
}
|
||||
|
||||
BBObj *_bbObjNext( BBObj *obj ){
|
||||
do{
|
||||
obj=obj->next;
|
||||
if( !obj->type ) return 0;
|
||||
}while( !obj->fields );
|
||||
return obj;
|
||||
}
|
||||
|
||||
BBObj *_bbObjPrev( BBObj *obj ){
|
||||
do{
|
||||
obj=obj->prev;
|
||||
if( !obj->type ) return 0;
|
||||
}while( !obj->fields );
|
||||
return obj;
|
||||
}
|
||||
|
||||
BBObj *_bbObjFirst( BBObjType *type ){
|
||||
return _bbObjNext( &type->used );
|
||||
}
|
||||
|
||||
BBObj *_bbObjLast( BBObjType *type ){
|
||||
return _bbObjPrev( &type->used );
|
||||
}
|
||||
|
||||
void _bbObjInsBefore( BBObj *o1,BBObj *o2 ){
|
||||
if( o1==o2 ) return;
|
||||
unlinkObj( o1 );
|
||||
insertObj( o1,o2 );
|
||||
}
|
||||
|
||||
void _bbObjInsAfter( BBObj *o1,BBObj *o2 ){
|
||||
if( o1==o2 ) return;
|
||||
unlinkObj( o1 );
|
||||
insertObj( o1,o2->next );
|
||||
}
|
||||
|
||||
int _bbObjEachFirst( BBObj **var,BBObjType *type ){
|
||||
_bbObjStore( var,_bbObjFirst( type ) );
|
||||
return *var!=0;
|
||||
}
|
||||
|
||||
int _bbObjEachNext( BBObj **var ){
|
||||
_bbObjStore( var,_bbObjNext( *var ) );
|
||||
return *var!=0;
|
||||
}
|
||||
|
||||
int _bbObjEachFirst2( BBObj **var,BBObjType *type ){
|
||||
*var=_bbObjFirst( type );
|
||||
return *var!=0;
|
||||
}
|
||||
|
||||
int _bbObjEachNext2( BBObj **var ){
|
||||
*var=_bbObjNext( *var );
|
||||
return *var!=0;
|
||||
}
|
||||
|
||||
BBStr *_bbObjToStr( BBObj *obj ){
|
||||
if( !obj || !obj->fields ) return d_new BBStr( "[NULL]" );
|
||||
|
||||
static BBObj *root;
|
||||
static int recurs_cnt;
|
||||
|
||||
if( obj==root ) return d_new BBStr( "[ROOT]" );
|
||||
if( recurs_cnt==8 ) return d_new BBStr( "...." );
|
||||
|
||||
++recurs_cnt;
|
||||
BBObj *oldRoot=root;
|
||||
if( !root ) root=obj;
|
||||
|
||||
BBObjType *type=obj->type;
|
||||
BBField *fields=obj->fields;
|
||||
BBStr *s=d_new BBStr("["),*t;
|
||||
for( int k=0;k<type->fieldCnt;++k ){
|
||||
if( k ) *s+=',';
|
||||
switch( type->fieldTypes[k]->type ){
|
||||
case BBTYPE_INT:
|
||||
t=_bbStrFromInt( fields[k].INT );*s+=*t;delete t;
|
||||
break;
|
||||
case BBTYPE_FLT:
|
||||
t=_bbStrFromFloat( fields[k].FLT );*s+=*t;delete t;
|
||||
break;
|
||||
case BBTYPE_STR:
|
||||
if( fields[k].STR ) *s+='\"'+*fields[k].STR+'\"';
|
||||
else *s+="\"\"";
|
||||
break;
|
||||
case BBTYPE_OBJ:
|
||||
t=_bbObjToStr( fields[k].OBJ );*s+=*t;delete t;
|
||||
break;
|
||||
default:
|
||||
*s+="???";
|
||||
}
|
||||
}
|
||||
*s+=']';
|
||||
root=oldRoot;
|
||||
--recurs_cnt;
|
||||
return s;
|
||||
}
|
||||
|
||||
int _bbObjToHandle( BBObj *obj ){
|
||||
if( !obj || !obj->fields ) return 0;
|
||||
map<BBObj*,int>::const_iterator it=object_map.find( obj );
|
||||
if( it!=object_map.end() ) return it->second;
|
||||
++next_handle;
|
||||
object_map[obj]=next_handle;
|
||||
handle_map[next_handle]=obj;
|
||||
return next_handle;
|
||||
}
|
||||
|
||||
BBObj *_bbObjFromHandle( int handle,BBObjType *type ){
|
||||
map<int,BBObj*>::const_iterator it=handle_map.find( handle );
|
||||
if( it==handle_map.end() ) return 0;
|
||||
BBObj *obj=it->second;
|
||||
return obj->type==type ? obj : 0;
|
||||
}
|
||||
|
||||
void _bbNullObjEx(){
|
||||
ThrowRuntimeException( "Object does not exist" );
|
||||
}
|
||||
|
||||
void _bbRestore( BBData *data ){
|
||||
dataPtr=data;
|
||||
}
|
||||
|
||||
int _bbReadInt(){
|
||||
switch( dataPtr->fieldType ){
|
||||
case BBTYPE_END:ThrowRuntimeException( "Out of data" );return 0;
|
||||
case BBTYPE_INT:return dataPtr++->field.INT;
|
||||
case BBTYPE_FLT:return dataPtr++->field.FLT;
|
||||
case BBTYPE_CSTR:return atoi( dataPtr++->field.CSTR );
|
||||
default:ThrowRuntimeException( "Bad data type" );return 0;
|
||||
}
|
||||
}
|
||||
|
||||
float _bbReadFloat(){
|
||||
switch( dataPtr->fieldType ){
|
||||
case BBTYPE_END:ThrowRuntimeException( "Out of data" );return 0;
|
||||
case BBTYPE_INT:return dataPtr++->field.INT;
|
||||
case BBTYPE_FLT:return dataPtr++->field.FLT;
|
||||
case BBTYPE_CSTR:return atof( dataPtr++->field.CSTR );
|
||||
default:ThrowRuntimeException( "Bad data type" );return 0;
|
||||
}
|
||||
}
|
||||
|
||||
BBStr *_bbReadStr(){
|
||||
switch( dataPtr->fieldType ){
|
||||
case BBTYPE_END:ThrowRuntimeException( "Out of data" );return 0;
|
||||
case BBTYPE_INT:return d_new BBStr( itoa( dataPtr++->field.INT ) );
|
||||
case BBTYPE_FLT:return d_new BBStr( ftoa( dataPtr++->field.FLT ) );
|
||||
case BBTYPE_CSTR:return d_new BBStr( dataPtr++->field.CSTR );
|
||||
default:ThrowRuntimeException( "Bad data type" );return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int _bbAbs( int n ){
|
||||
return n>=0 ? n : -n;
|
||||
}
|
||||
|
||||
int _bbSgn( int n ){
|
||||
return n>0 ? 1 : (n<0 ? -1 : 0);
|
||||
}
|
||||
|
||||
int _bbMod( int x,int y ){
|
||||
return x%y;
|
||||
}
|
||||
|
||||
float _bbFAbs( float n ){
|
||||
return n>=0 ? n : -n;
|
||||
}
|
||||
|
||||
float _bbFSgn( float n ){
|
||||
return n>0 ? 1 : (n<0 ? -1 : 0);
|
||||
}
|
||||
|
||||
float _bbFMod( float x,float y ){
|
||||
return (float)fmod( x,y );
|
||||
}
|
||||
|
||||
float _bbFPow( float x,float y ){
|
||||
return (float)pow( x,y );
|
||||
}
|
||||
|
||||
void bbRuntimeStats(){
|
||||
gx_runtime->debugLog( ("Active strings :"+itoa(stringCnt)).c_str() );
|
||||
gx_runtime->debugLog( ("Active objects :"+itoa(objCnt)).c_str() );
|
||||
gx_runtime->debugLog( ("Unreleased objs:"+itoa(unrelObjCnt)).c_str() );
|
||||
/*
|
||||
clog<<"Active strings:"<<stringCnt<<endl;
|
||||
clog<<"Active objects:"<<objCnt<<endl;
|
||||
clog<<"Unreleased Objects:"<<unrelObjCnt<<endl;
|
||||
for( BBStr *t=usedStrs.next;t!=&usedStrs;t=t->next ){
|
||||
clog<<"string@"<<(void*)t<<endl;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
bool basic_create(){
|
||||
next_handle=0;
|
||||
// memBlks.clear();
|
||||
handle_map.clear();
|
||||
object_map.clear();
|
||||
stringCnt=objCnt=unrelObjCnt=0;
|
||||
usedStrs.next=usedStrs.prev=&usedStrs;
|
||||
freeStrs.next=freeStrs.prev=&freeStrs;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool basic_destroy(){
|
||||
while( usedStrs.next!=&usedStrs ) delete usedStrs.next;
|
||||
// while( memBlks.size() ) bbFree( memBlks.back() );
|
||||
handle_map.clear();
|
||||
object_map.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
void basic_link( void (*rtSym)( const char *sym,void *pc ) ){
|
||||
|
||||
rtSym( "_bbIntType",&_bbIntType );
|
||||
rtSym( "_bbFltType",&_bbFltType );
|
||||
rtSym( "_bbStrType",&_bbStrType );
|
||||
rtSym( "_bbCStrType",&_bbCStrType );
|
||||
|
||||
rtSym( "_bbStrLoad",_bbStrLoad );
|
||||
rtSym( "_bbStrRelease",_bbStrRelease );
|
||||
rtSym( "_bbStrStore",_bbStrStore );
|
||||
rtSym( "_bbStrCompare",_bbStrCompare );
|
||||
rtSym( "_bbStrConcat",_bbStrConcat );
|
||||
rtSym( "_bbStrToInt",_bbStrToInt );
|
||||
rtSym( "_bbStrFromInt",_bbStrFromInt );
|
||||
rtSym( "_bbStrToFloat",_bbStrToFloat );
|
||||
rtSym( "_bbStrFromFloat",_bbStrFromFloat );
|
||||
rtSym( "_bbStrConst",_bbStrConst );
|
||||
rtSym( "_bbDimArray",_bbDimArray );
|
||||
rtSym( "_bbUndimArray",_bbUndimArray );
|
||||
rtSym( "_bbArrayBoundsEx",_bbArrayBoundsEx );
|
||||
rtSym( "_bbVecAlloc",_bbVecAlloc );
|
||||
rtSym( "_bbVecFree",_bbVecFree );
|
||||
rtSym( "_bbVecBoundsEx",_bbVecBoundsEx );
|
||||
rtSym( "_bbObjNew",_bbObjNew );
|
||||
rtSym( "_bbObjDelete",_bbObjDelete );
|
||||
rtSym( "_bbObjDeleteEach",_bbObjDeleteEach );
|
||||
rtSym( "_bbObjRelease",_bbObjRelease );
|
||||
rtSym( "_bbObjStore",_bbObjStore );
|
||||
rtSym( "_bbObjCompare",_bbObjCompare );
|
||||
rtSym( "_bbObjNext",_bbObjNext );
|
||||
rtSym( "_bbObjPrev",_bbObjPrev );
|
||||
rtSym( "_bbObjFirst",_bbObjFirst );
|
||||
rtSym( "_bbObjLast",_bbObjLast );
|
||||
rtSym( "_bbObjInsBefore",_bbObjInsBefore );
|
||||
rtSym( "_bbObjInsAfter",_bbObjInsAfter );
|
||||
rtSym( "_bbObjEachFirst",_bbObjEachFirst );
|
||||
rtSym( "_bbObjEachNext",_bbObjEachNext );
|
||||
rtSym( "_bbObjEachFirst2",_bbObjEachFirst2 );
|
||||
rtSym( "_bbObjEachNext2",_bbObjEachNext2 );
|
||||
rtSym( "_bbObjToStr",_bbObjToStr );
|
||||
rtSym( "_bbObjToHandle",_bbObjToHandle );
|
||||
rtSym( "_bbObjFromHandle",_bbObjFromHandle );
|
||||
rtSym( "_bbNullObjEx",_bbNullObjEx );
|
||||
rtSym( "_bbRestore",_bbRestore );
|
||||
rtSym( "_bbReadInt",_bbReadInt );
|
||||
rtSym( "_bbReadFloat",_bbReadFloat );
|
||||
rtSym( "_bbReadStr",_bbReadStr );
|
||||
rtSym( "_bbAbs",_bbAbs );
|
||||
rtSym( "_bbSgn",_bbSgn );
|
||||
rtSym( "_bbMod",_bbMod );
|
||||
rtSym( "_bbFAbs",_bbFAbs );
|
||||
rtSym( "_bbFSgn",_bbFSgn );
|
||||
rtSym( "_bbFMod",_bbFMod );
|
||||
rtSym( "_bbFPow",_bbFPow );
|
||||
rtSym( "RuntimeStats",bbRuntimeStats );
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
|
||||
#ifndef BASIC_H
|
||||
#define BASIC_H
|
||||
|
||||
#include <string>
|
||||
|
||||
enum{
|
||||
BBTYPE_END=0,
|
||||
BBTYPE_INT=1,BBTYPE_FLT=2,
|
||||
BBTYPE_STR=3,BBTYPE_CSTR=4,
|
||||
BBTYPE_OBJ=5,BBTYPE_VEC=6
|
||||
};
|
||||
|
||||
#pragma pack( push,1 )
|
||||
|
||||
struct BBObj;
|
||||
struct BBStr;
|
||||
struct BBType;
|
||||
struct BBObjType;
|
||||
struct BBVecType;
|
||||
union BBField;
|
||||
struct BBArray;
|
||||
|
||||
struct BBObj{
|
||||
BBField *fields;
|
||||
BBObj *next,*prev;
|
||||
BBObjType *type;
|
||||
int ref_cnt;
|
||||
};
|
||||
|
||||
struct BBType{
|
||||
int type;
|
||||
BBType( int n ):type(n){}
|
||||
};
|
||||
|
||||
struct BBObjType : public BBType{
|
||||
BBObj used,free;
|
||||
int fieldCnt;
|
||||
BBType *fieldTypes[1];
|
||||
};
|
||||
|
||||
struct BBVecType : public BBType{
|
||||
int size;
|
||||
BBType *elementType;
|
||||
};
|
||||
|
||||
union BBField{
|
||||
int INT;
|
||||
float FLT;
|
||||
BBStr *STR;
|
||||
char *CSTR;
|
||||
BBObj *OBJ;
|
||||
void *VEC;
|
||||
};
|
||||
|
||||
struct BBArray{
|
||||
void *data;
|
||||
int elementType,dims,scales[1];
|
||||
};
|
||||
|
||||
struct BBStr : public std::string{
|
||||
BBStr *next,*prev;
|
||||
|
||||
BBStr();
|
||||
BBStr( const char *s );
|
||||
BBStr( const char *s,int n );
|
||||
BBStr( const BBStr &s );
|
||||
BBStr( const std::string &s );
|
||||
BBStr &operator=( const char *s );
|
||||
BBStr &operator=( const BBStr &s );
|
||||
BBStr &operator=( const std::string &s );
|
||||
~BBStr();
|
||||
|
||||
void *operator new( size_t size );
|
||||
void operator delete( void *q );
|
||||
|
||||
void *operator new( size_t size,const char *file,int line ){ return operator new( size ); }
|
||||
void operator delete( void *q,const char *file,int line ){ operator delete( q ); }
|
||||
};
|
||||
|
||||
struct BBData{
|
||||
int fieldType;
|
||||
BBField field;
|
||||
};
|
||||
|
||||
#pragma pack( pop )
|
||||
|
||||
void basic_link();
|
||||
|
||||
extern BBType _bbIntType;
|
||||
extern BBType _bbFltType;
|
||||
extern BBType _bbStrType;
|
||||
extern BBType _bbCStrType;
|
||||
|
||||
BBStr * _bbStrLoad( BBStr **var );
|
||||
void _bbStrRelease( BBStr *str );
|
||||
void _bbStrStore( BBStr **var,BBStr *str );
|
||||
int _bbStrCompare( BBStr *lhs,BBStr *rhs );
|
||||
|
||||
BBStr * _bbStrConcat( BBStr *s1,BBStr *s2 );
|
||||
int _bbStrToInt( BBStr *s );
|
||||
BBStr * _bbStrFromInt( int n );
|
||||
float _bbStrToFloat( BBStr *s );
|
||||
BBStr * _bbStrFromFloat( float n );
|
||||
BBStr * _bbStrConst( const char *s );
|
||||
|
||||
void _bbDimArray( BBArray *array );
|
||||
void _bbUndimArray( BBArray *array );
|
||||
void _bbArrayBoundsEx();
|
||||
|
||||
void * _bbVecAlloc( BBVecType *type );
|
||||
void _bbVecFree( void *vec,BBVecType *type );
|
||||
void _bbVecBoundsEx();
|
||||
|
||||
BBObj * _bbObjNew( BBObjType *t );
|
||||
void _bbObjDelete( BBObj *obj );
|
||||
void _bbObjDeleteEach( BBObjType *type );
|
||||
void _bbObjRelease( BBObj *obj );
|
||||
void _bbObjStore( BBObj **var,BBObj *obj );
|
||||
BBObj * _bbObjNext( BBObj *obj );
|
||||
BBObj * _bbObjPrev( BBObj *obj );
|
||||
BBObj * _bbObjFirst( BBObjType *t );
|
||||
BBObj * _bbObjLast( BBObjType *t );
|
||||
void _bbObjInsBefore( BBObj *o1,BBObj *o2 );
|
||||
void _bbObjInsAfter( BBObj *o1,BBObj *o2 );
|
||||
int _bbObjEachFirst( BBObj **var,BBObjType *type );
|
||||
int _bbObjEachNext( BBObj **var );
|
||||
int _bbObjCompare( BBObj *o1,BBObj *o2 );
|
||||
BBStr * _bbObjToStr( BBObj *obj );
|
||||
int _bbObjToHandle( BBObj *obj );
|
||||
BBObj * _bbObjFromHandle( int handle,BBObjType *type );
|
||||
void _bbNullObjEx();
|
||||
|
||||
void _bbRestore( BBData *data );
|
||||
int _bbReadInt();
|
||||
float _bbReadFloat();
|
||||
BBStr * _bbReadStr();
|
||||
|
||||
int _bbAbs( int n );
|
||||
int _bbSgn( int n );
|
||||
int _bbMod( int x,int y );
|
||||
float _bbFAbs( float n );
|
||||
float _bbFSgn( float n );
|
||||
float _bbFMod( float x,float y );
|
||||
float _bbFPow( float x,float y );
|
||||
|
||||
void bbRuntimeStats();
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,82 @@
|
||||
|
||||
enum{
|
||||
BBTYPE_END=0,
|
||||
BBTYPE_INT=1,BBTYPE_FLOAT=2,
|
||||
BBTYPE_STRING=3,BBTYPE_CSTR=4,
|
||||
BBTYPE_OBJECT=5,BBTYPE_VECTOR=6
|
||||
};
|
||||
|
||||
typedef int bbInt;
|
||||
typedef float bbFloat;
|
||||
typedef bbStringhandle *bbString;
|
||||
typedef bbObjectHandle *bbObject;
|
||||
typedef bbVectorHandle *bbVector;
|
||||
typedef const char * bbCStr;
|
||||
|
||||
union bbValue{
|
||||
bbInt INT;
|
||||
bbFloat FLOAT;
|
||||
bbString STRING;
|
||||
bbObject OBJECT;
|
||||
bbVector VECTOR;
|
||||
bbCStr CSTR;
|
||||
};
|
||||
|
||||
struct bbType{
|
||||
int id;
|
||||
bbType( int n ):id(n(){}
|
||||
};
|
||||
|
||||
struct bbInstance{
|
||||
bbValue value;
|
||||
};
|
||||
|
||||
struct bbHandle{
|
||||
bbInstance *instance;
|
||||
int ref_cnt;
|
||||
bbType *type;
|
||||
};
|
||||
|
||||
struct bbEnviron{
|
||||
bbVector *variables;
|
||||
};
|
||||
|
||||
struct bbIntType : public bbType{
|
||||
bbInt():bbType( BBTYPE_INT ){}
|
||||
};
|
||||
|
||||
struct bbFloatType : public bbType{
|
||||
bbFloat():bbType( BBTYPE_FLOAT ){}
|
||||
};
|
||||
|
||||
struct bbCStrType : public bbType{
|
||||
bbCStrType():bbType( BBTYPE_CSTR ){}
|
||||
};
|
||||
|
||||
struct bbStringType : public bbType{
|
||||
bbStringType():bbType( BBTYPE_STRING ){}
|
||||
};
|
||||
|
||||
struct bbVectorType : public bbType{
|
||||
bbType *element_type;
|
||||
bbVectorType( bbType *e ):bbType( BBTYPE_VECTOR ),element_type( e ){}
|
||||
}
|
||||
|
||||
struct bbObjectType : public bbType{
|
||||
bbEnviron *environ;
|
||||
bbObject *first_used,*last_used;
|
||||
bbObject *first_free,*last_free;
|
||||
bbObjectType( bbEnviron *e ):bbType( BBTYPE_OBJECT ),environ( e ){}
|
||||
};
|
||||
|
||||
struct bbStringHandle : public bbHandle{
|
||||
};
|
||||
|
||||
struct bbObjectHandle : public bbHandle{
|
||||
bbObject *next,*prev;
|
||||
};
|
||||
|
||||
struct bbVectorHandle : public bbHandle{
|
||||
};
|
||||
|
||||
void assign( bbHandleVariable dest,bbHandle src );
|
||||
@@ -0,0 +1,138 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "bbaudio.h"
|
||||
|
||||
gxAudio *gx_audio;
|
||||
|
||||
static inline void debugSound( gxSound *s ){
|
||||
if( debug ){
|
||||
if( !gx_audio->verifySound( s ) ) ThrowRuntimeException( "Sound does not exist" );
|
||||
}
|
||||
}
|
||||
|
||||
static gxSound *loadSound( BBStr *f,bool use_3d ){
|
||||
string t=*f;delete f;
|
||||
return gx_audio ? gx_audio->loadSound( t,use_3d ) : 0;
|
||||
}
|
||||
|
||||
static gxChannel *playMusic( BBStr *f,bool use_3d ){
|
||||
string t=*f;delete f;
|
||||
return gx_audio ? gx_audio->playFile( t,use_3d ) : 0;
|
||||
}
|
||||
|
||||
gxSound *bbLoadSound( BBStr *f ){
|
||||
return loadSound( f,false );
|
||||
}
|
||||
|
||||
void bbFreeSound( gxSound *sound ){
|
||||
if( !sound ) return;
|
||||
debugSound( sound );
|
||||
gx_audio->freeSound( sound );
|
||||
}
|
||||
|
||||
void bbLoopSound( gxSound *sound ){
|
||||
if( !sound ) return;
|
||||
debugSound( sound );
|
||||
sound->setLoop( true );
|
||||
}
|
||||
|
||||
void bbSoundPitch( gxSound *sound,int pitch ){
|
||||
if( !sound ) return;
|
||||
debugSound( sound );
|
||||
sound->setPitch( pitch );
|
||||
}
|
||||
|
||||
void bbSoundVolume( gxSound *sound,float volume ){
|
||||
if( !sound ) return;
|
||||
debugSound( sound );
|
||||
sound->setVolume( volume );
|
||||
}
|
||||
|
||||
void bbSoundPan( gxSound *sound,float pan ){
|
||||
if( !sound ) return;
|
||||
debugSound( sound );
|
||||
sound->setPan( pan );
|
||||
}
|
||||
|
||||
gxChannel *bbPlaySound( gxSound *sound ){
|
||||
if( !sound ) return 0;
|
||||
debugSound( sound );
|
||||
return sound->play();
|
||||
}
|
||||
|
||||
gxChannel *bbPlayMusic( BBStr *f ){
|
||||
return playMusic( f,false );
|
||||
}
|
||||
|
||||
gxChannel *bbPlayCDTrack( int track,int mode ){
|
||||
return gx_audio ? gx_audio->playCDTrack( track,mode ) : 0;
|
||||
}
|
||||
|
||||
void bbStopChannel( gxChannel *channel ){
|
||||
if( !channel ) return;
|
||||
channel->stop();
|
||||
}
|
||||
|
||||
void bbPauseChannel( gxChannel *channel ){
|
||||
if( !channel ) return;
|
||||
channel->setPaused( true );
|
||||
}
|
||||
|
||||
void bbResumeChannel( gxChannel *channel ){
|
||||
if( !channel ) return;
|
||||
channel->setPaused( false );
|
||||
}
|
||||
|
||||
void bbChannelPitch( gxChannel *channel,int pitch ){
|
||||
if( !channel ) return;
|
||||
channel->setPitch( pitch );
|
||||
}
|
||||
|
||||
void bbChannelVolume( gxChannel *channel,float volume ){
|
||||
if( !channel ) return;
|
||||
channel->setVolume( volume );
|
||||
}
|
||||
|
||||
void bbChannelPan( gxChannel *channel,float pan ){
|
||||
if( !channel ) return;
|
||||
channel->setPan( pan );
|
||||
}
|
||||
|
||||
int bbChannelPlaying( gxChannel *channel ){
|
||||
return channel ? channel->isPlaying() : 0;
|
||||
}
|
||||
|
||||
gxSound *bbLoad3DSound( BBStr *f ){
|
||||
return loadSound( f,true );
|
||||
}
|
||||
|
||||
bool audio_create(){
|
||||
gx_audio=gx_runtime->openAudio( 0 );
|
||||
return true;
|
||||
}
|
||||
|
||||
bool audio_destroy(){
|
||||
if( gx_audio ) gx_runtime->closeAudio( gx_audio );
|
||||
gx_audio=0;
|
||||
return true;
|
||||
}
|
||||
|
||||
void audio_link( void(*rtSym)(const char*,void*) ){
|
||||
rtSym( "%LoadSound$filename",bbLoadSound );
|
||||
rtSym( "FreeSound%sound",bbFreeSound );
|
||||
rtSym( "LoopSound%sound",bbLoopSound );
|
||||
rtSym( "SoundPitch%sound%pitch",bbSoundPitch );
|
||||
rtSym( "SoundVolume%sound#volume",bbSoundVolume );
|
||||
rtSym( "SoundPan%sound#pan",bbSoundPan );
|
||||
rtSym( "%PlaySound%sound",bbPlaySound );
|
||||
rtSym( "%PlayMusic$midifile",bbPlayMusic );
|
||||
rtSym( "%PlayCDTrack%track%mode=1",bbPlayCDTrack );
|
||||
rtSym( "StopChannel%channel",bbStopChannel );
|
||||
rtSym( "PauseChannel%channel",bbPauseChannel );
|
||||
rtSym( "ResumeChannel%channel",bbResumeChannel );
|
||||
rtSym( "ChannelPitch%channel%pitch",bbChannelPitch );
|
||||
rtSym( "ChannelVolume%channel#volume",bbChannelVolume );
|
||||
rtSym( "ChannelPan%channel#pan",bbChannelPan );
|
||||
rtSym( "%ChannelPlaying%channel",bbChannelPlaying );
|
||||
rtSym( "%Load3DSound$filename",bbLoad3DSound );
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
|
||||
#ifndef BBAUDIO_H
|
||||
#define BBAUDIO_H
|
||||
|
||||
#include "bbsys.h"
|
||||
#include "../gxruntime/gxaudio.h"
|
||||
|
||||
extern gxAudio *gx_audio;
|
||||
|
||||
gxSound * bbLoadSound( BBStr *file );
|
||||
void bbFreeSound( gxSound *sound );
|
||||
gxChannel * bbPlaySound( gxSound *sound );
|
||||
void bbLoopSound( gxSound *sound );
|
||||
void bbSoundPitch( gxSound *sound,int pitch );
|
||||
void bbSoundVolume( gxSound *sound,float volume );
|
||||
void bbSoundPan( gxSound *sound,float pan );
|
||||
gxChannel * bbPlayMusic( BBStr *s );
|
||||
gxChannel * bbPlayCDTrack( int track,int mode );
|
||||
void bbStopChannel( gxChannel *channel );
|
||||
void bbPauseChannel( gxChannel *channel );
|
||||
void bbResumeChannel( gxChannel *channel );
|
||||
void bbChannelPitch( gxChannel *channel,int pitch );
|
||||
void bbChannelVolume( gxChannel *channel,float volume );
|
||||
void bbChannelPan( gxChannel *channel,float pan );
|
||||
int bbChannelPlaying( gxChannel *channel );
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "bbbank.h"
|
||||
#include "bbstream.h"
|
||||
|
||||
struct bbBank{
|
||||
char *data;
|
||||
int size,capacity;
|
||||
|
||||
bbBank( int sz ):size(sz){
|
||||
capacity=(size+15)&~15;
|
||||
data=d_new char[capacity];
|
||||
memset( data,0,size );
|
||||
}
|
||||
virtual ~bbBank(){
|
||||
delete[] data;
|
||||
}
|
||||
void resize( int n ){
|
||||
if( n>size ){
|
||||
if( n>capacity ){
|
||||
capacity=capacity*3/2;
|
||||
if( n>capacity ) capacity=n;
|
||||
capacity=(capacity+15)&~15;
|
||||
char *p=d_new char[capacity];
|
||||
memcpy( p,data,size );
|
||||
delete[] data;
|
||||
data=p;
|
||||
}else memset( data+size,0,n-size );
|
||||
}
|
||||
size=n;
|
||||
}
|
||||
};
|
||||
|
||||
static set<bbBank*> bank_set;
|
||||
|
||||
static inline void debugBank( bbBank *b ){
|
||||
if( debug ){
|
||||
if( !bank_set.count( b ) ) ThrowRuntimeException( "bbBank does not exist" );
|
||||
}
|
||||
}
|
||||
|
||||
static inline void debugBank( bbBank *b,int offset ){
|
||||
if( debug ){
|
||||
debugBank( b );
|
||||
if( offset>=b->size ) ThrowRuntimeException( "Offset out of range" );
|
||||
}
|
||||
}
|
||||
|
||||
bbBank *bbCreateBank( int size ){
|
||||
bbBank *b=d_new bbBank( size );
|
||||
bank_set.insert( b );
|
||||
return b;
|
||||
}
|
||||
|
||||
void bbFreeBank( bbBank *b ){
|
||||
if( bank_set.erase( b ) ) delete b;
|
||||
}
|
||||
|
||||
int bbBankSize( bbBank *b ){
|
||||
debugBank( b );
|
||||
return b->size;
|
||||
}
|
||||
|
||||
void bbResizeBank( bbBank *b,int size ){
|
||||
debugBank( b );
|
||||
b->resize( size );
|
||||
}
|
||||
|
||||
void bbCopyBank( bbBank *src,int src_p,bbBank *dest,int dest_p,int count ){
|
||||
if( debug ){ debugBank( src,src_p+count-1 );debugBank( dest,dest_p+count-1 ); }
|
||||
memmove( dest->data+dest_p,src->data+src_p,count );
|
||||
}
|
||||
|
||||
int bbPeekByte( bbBank *b,int offset ){
|
||||
debugBank( b,offset );
|
||||
return *(unsigned char*)(b->data+offset);
|
||||
}
|
||||
|
||||
int bbPeekShort( bbBank *b,int offset ){
|
||||
debugBank( b,offset+1 );
|
||||
return *(unsigned short*)(b->data+offset);
|
||||
}
|
||||
|
||||
int bbPeekInt( bbBank *b,int offset ){
|
||||
debugBank( b,offset+3 );
|
||||
return *(int*)(b->data+offset);
|
||||
}
|
||||
|
||||
float bbPeekFloat( bbBank *b,int offset ){
|
||||
debugBank( b,offset+3 );
|
||||
return *(float*)(b->data+offset);
|
||||
}
|
||||
|
||||
void bbPokeByte( bbBank *b,int offset,int value ){
|
||||
debugBank( b,offset );
|
||||
*(char*)(b->data+offset)=value;
|
||||
}
|
||||
|
||||
void bbPokeShort( bbBank *b,int offset,int value ){
|
||||
debugBank( b,offset );
|
||||
*(unsigned short*)(b->data+offset)=value;
|
||||
}
|
||||
|
||||
void bbPokeInt( bbBank *b,int offset,int value ){
|
||||
debugBank( b,offset );
|
||||
*(int*)(b->data+offset)=value;
|
||||
}
|
||||
|
||||
void bbPokeFloat( bbBank *b,int offset,float value ){
|
||||
debugBank( b,offset );
|
||||
*(float*)(b->data+offset)=value;
|
||||
}
|
||||
|
||||
int bbReadBytes( bbBank *b,bbStream *s,int offset,int count ){
|
||||
if( debug ){
|
||||
debugBank( b,offset+count-1 );
|
||||
debugStream( s );
|
||||
}
|
||||
return s->read( b->data+offset,count );
|
||||
}
|
||||
|
||||
int bbWriteBytes( bbBank *b,bbStream *s,int offset,int count ){
|
||||
if( debug ){
|
||||
debugBank( b,offset+count-1 );
|
||||
debugStream( s );
|
||||
}
|
||||
return s->write( b->data+offset,count );
|
||||
}
|
||||
|
||||
int bbCallDLL( BBStr *dll,BBStr *fun,bbBank *in,bbBank *out ){
|
||||
if( debug ){
|
||||
if( in ) debugBank( in );
|
||||
if( out ) debugBank( out );
|
||||
}
|
||||
int t=gx_runtime->callDll( *dll,*fun,
|
||||
in ? in->data : 0,in ? in->size : 0,
|
||||
out ? out->data : 0,out ? out->size : 0 );
|
||||
delete dll;delete fun;
|
||||
return t;
|
||||
}
|
||||
|
||||
bool bank_create(){
|
||||
return true;
|
||||
}
|
||||
|
||||
bool bank_destroy(){
|
||||
while( bank_set.size() ) bbFreeBank( *bank_set.begin() );
|
||||
return true;
|
||||
}
|
||||
|
||||
void bank_link( void(*rtSym)(const char*,void*) ){
|
||||
rtSym( "%CreateBank%size=0",bbCreateBank );
|
||||
rtSym( "FreeBank%bank",bbFreeBank );
|
||||
rtSym( "%BankSize%bank",bbBankSize );
|
||||
rtSym( "ResizeBank%bank%size",bbResizeBank );
|
||||
rtSym( "CopyBank%src_bank%src_offset%dest_bank%dest_offset%count",bbCopyBank );
|
||||
rtSym( "%PeekByte%bank%offset",bbPeekByte );
|
||||
rtSym( "%PeekShort%bank%offset",bbPeekShort );
|
||||
rtSym( "%PeekInt%bank%offset",bbPeekInt );
|
||||
rtSym( "#PeekFloat%bank%offset",bbPeekFloat );
|
||||
rtSym( "PokeByte%bank%offset%value",bbPokeByte );
|
||||
rtSym( "PokeShort%bank%offset%value",bbPokeShort );
|
||||
rtSym( "PokeInt%bank%offset%value",bbPokeInt );
|
||||
rtSym( "PokeFloat%bank%offset#value",bbPokeFloat );
|
||||
rtSym( "%ReadBytes%bank%file%offset%count",bbReadBytes );
|
||||
rtSym( "%WriteBytes%bank%file%offset%count",bbWriteBytes );
|
||||
rtSym( "%CallDLL$dll_name$func_name%in_bank=0%out_bank=0",bbCallDLL );
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
#ifndef BBBANK_H
|
||||
#define BBBANK_H
|
||||
|
||||
#include "bbsys.h"
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
|
||||
#ifndef BBBLITZ3D_H
|
||||
#define BBBLITZ3D_H
|
||||
|
||||
#include "bbsys.h"
|
||||
#include "../gxruntime/gxscene.h"
|
||||
|
||||
extern gxScene *gx_scene;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "bbfilesystem.h"
|
||||
#include "bbstream.h"
|
||||
#include <fstream>
|
||||
|
||||
gxFileSystem *gx_filesys;
|
||||
|
||||
struct bbFile : public bbStream{
|
||||
filebuf *buf;
|
||||
bbFile( filebuf *f ):buf(f){
|
||||
}
|
||||
~bbFile(){
|
||||
delete buf;
|
||||
}
|
||||
int read( char *buff,int size ){
|
||||
return buf->sgetn( (char*)buff,size );
|
||||
}
|
||||
int write( const char *buff,int size ){
|
||||
return buf->sputn( (char*)buff,size );
|
||||
}
|
||||
int avail(){
|
||||
return buf->in_avail();
|
||||
}
|
||||
int eof(){
|
||||
return buf->sgetc()==EOF;
|
||||
}
|
||||
};
|
||||
|
||||
static set<bbFile*> file_set;
|
||||
|
||||
static inline void debugFile( bbFile *f ){
|
||||
if( debug ){
|
||||
if( !file_set.count( f ) ) ThrowRuntimeException( "File does not exist" );
|
||||
}
|
||||
}
|
||||
|
||||
static inline void debugDir( gxDir *d ){
|
||||
if( debug ){
|
||||
if( !gx_filesys->verifyDir( d ) ) ThrowRuntimeException( "Directory does not exist" );
|
||||
}
|
||||
}
|
||||
|
||||
static bbFile *open( BBStr *f,int n ){
|
||||
string t=*f;
|
||||
filebuf *buf=d_new filebuf();
|
||||
if( buf->open( t.c_str(),n|ios_base::binary ) ){
|
||||
bbFile *f=d_new bbFile( buf );
|
||||
file_set.insert( f );
|
||||
return f;
|
||||
}
|
||||
delete buf;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bbFile *bbReadFile( BBStr *f ){
|
||||
return open( f,ios_base::in );
|
||||
}
|
||||
|
||||
bbFile *bbWriteFile( BBStr *f ){
|
||||
return open( f,ios_base::out|ios_base::trunc );
|
||||
}
|
||||
|
||||
bbFile *bbOpenFile( BBStr *f ){
|
||||
return open( f,ios_base::in|ios_base::out );
|
||||
}
|
||||
|
||||
void bbCloseFile( bbFile *f ){
|
||||
debugFile( f );
|
||||
file_set.erase( f );
|
||||
delete f;
|
||||
}
|
||||
|
||||
int bbFilePos( bbFile *f ){
|
||||
return f->buf->pubseekoff( 0,ios_base::cur );
|
||||
}
|
||||
|
||||
int bbSeekFile( bbFile *f,int pos ){
|
||||
return f->buf->pubseekoff( pos,ios_base::beg );
|
||||
}
|
||||
|
||||
gxDir *bbReadDir( BBStr *d ){
|
||||
string t=*d;delete d;
|
||||
return gx_filesys->openDir( t,0 );
|
||||
}
|
||||
|
||||
void bbCloseDir( gxDir *d ){
|
||||
gx_filesys->closeDir( d );
|
||||
}
|
||||
|
||||
BBStr *bbNextFile( gxDir *d ){
|
||||
debugDir( d );
|
||||
return d_new BBStr( d->getNextFile() );
|
||||
}
|
||||
|
||||
BBStr *bbCurrentDir(){
|
||||
return d_new BBStr( gx_filesys->getCurrentDir() );
|
||||
}
|
||||
|
||||
void bbChangeDir( BBStr *d ){
|
||||
gx_filesys->setCurrentDir( *d );
|
||||
delete d;
|
||||
}
|
||||
|
||||
void bbCreateDir( BBStr *d ){
|
||||
gx_filesys->createDir( *d );
|
||||
delete d;
|
||||
}
|
||||
|
||||
void bbDeleteDir( BBStr *d ){
|
||||
gx_filesys->deleteDir( *d );
|
||||
delete d;
|
||||
}
|
||||
|
||||
int bbFileType( BBStr *f ){
|
||||
string t=*f;delete f;
|
||||
int n=gx_filesys->getFileType( t );
|
||||
return n==gxFileSystem::FILE_TYPE_FILE ? 1 : (n==gxFileSystem::FILE_TYPE_DIR ? 2 : 0);
|
||||
}
|
||||
|
||||
int bbFileSize( BBStr *f ){
|
||||
string t=*f;delete f;
|
||||
return gx_filesys->getFileSize( t );
|
||||
}
|
||||
|
||||
void bbCopyFile( BBStr *f,BBStr *to ){
|
||||
string src=*f,dest=*to;
|
||||
delete f;delete to;
|
||||
gx_filesys->copyFile( src,dest );
|
||||
}
|
||||
|
||||
void bbDeleteFile( BBStr *f ){
|
||||
gx_filesys->deleteFile( *f );
|
||||
delete f;
|
||||
}
|
||||
|
||||
bool filesystem_create(){
|
||||
if( gx_filesys=gx_runtime->openFileSystem( 0 ) ){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool filesystem_destroy(){
|
||||
while( file_set.size() ) bbCloseFile( *file_set.begin() );
|
||||
gx_runtime->closeFileSystem( gx_filesys );
|
||||
return true;
|
||||
}
|
||||
|
||||
void filesystem_link( void(*rtSym)(const char*,void*) ){
|
||||
rtSym( "%OpenFile$filename",bbOpenFile );
|
||||
rtSym( "%ReadFile$filename",bbReadFile );
|
||||
rtSym( "%WriteFile$filename",bbWriteFile );
|
||||
rtSym( "CloseFile%file_stream",bbCloseFile );
|
||||
rtSym( "%FilePos%file_stream",bbFilePos );
|
||||
rtSym( "%SeekFile%file_stream%pos",bbSeekFile );
|
||||
|
||||
rtSym( "%ReadDir$dirname",bbReadDir );
|
||||
rtSym( "CloseDir%dir",bbCloseDir );
|
||||
rtSym( "$NextFile%dir",bbNextFile );
|
||||
rtSym( "$CurrentDir",bbCurrentDir );
|
||||
rtSym( "ChangeDir$dir",bbChangeDir );
|
||||
rtSym( "CreateDir$dir",bbCreateDir );
|
||||
rtSym( "DeleteDir$dir",bbDeleteDir );
|
||||
|
||||
rtSym( "%FileSize$file",bbFileSize );
|
||||
rtSym( "%FileType$file",bbFileType );
|
||||
rtSym( "CopyFile$file$to",bbCopyFile );
|
||||
rtSym( "DeleteFile$file",bbDeleteFile );
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
|
||||
#ifndef BBFILESYSTEM_H
|
||||
#define BBFILESYSTEM_H
|
||||
|
||||
#include "bbsys.h"
|
||||
#include "../gxruntime/gxfilesystem.h"
|
||||
|
||||
extern gxFileSystem *gx_filesys;
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,120 @@
|
||||
|
||||
#ifndef BBGRAPHICS_H
|
||||
#define BBGRAPHICS_H
|
||||
|
||||
#include "bbsys.h"
|
||||
#include "../gxruntime/gxgraphics.h"
|
||||
|
||||
extern gxGraphics *gx_graphics;
|
||||
extern gxCanvas *gx_canvas;
|
||||
extern gxScene *gx_scene;
|
||||
|
||||
class bbImage;
|
||||
|
||||
//general graphics functions
|
||||
int bbCountGfxDrivers();
|
||||
BBStr * bbGfxDriverName( int n );
|
||||
BBStr * bbGfxDriverDesc( int n );
|
||||
void bbSetGfxDriver( int n );
|
||||
int bbGfxModeExists( int w,int h,int d );
|
||||
int bbCountGfxModes();
|
||||
int bbGfxModeWidth( int n );
|
||||
int bbGfxModeHeight( int n );
|
||||
int bbGfxModeDepth( int n );
|
||||
int bbGraphicsWidth();
|
||||
int bbGraphicsHeight();
|
||||
int bbGraphicsDepth();
|
||||
int bbAvailVidMem();
|
||||
int bbTotalVidMem();
|
||||
|
||||
//mode functions
|
||||
void bbGraphics( int w,int h,int d,int mode );
|
||||
gxCanvas * bbFrontBuffer();
|
||||
gxCanvas * bbBackBuffer();
|
||||
void bbEndGraphics();
|
||||
int bbGraphicsLost();
|
||||
int bbScanLine();
|
||||
void bbVWait( int n );
|
||||
void bbFlip( int vwait );
|
||||
|
||||
//graphics buffer functions
|
||||
void bbSetBuffer( gxCanvas *buff );
|
||||
gxCanvas * bbGraphicsBuffer();
|
||||
int bbLoadBuffer( gxCanvas *surf,BBStr *str );
|
||||
int bbSaveBuffer( gxCanvas *surf,BBStr *str );
|
||||
|
||||
//fast read/write operations...
|
||||
void bbLockBuffer( gxCanvas *buff );
|
||||
void bbUnlockBuffer( gxCanvas *buff );
|
||||
int bbReadPixel( int x,int y,gxCanvas *buff );
|
||||
void bbWritePixel( int x,int y,int argb,gxCanvas *buff );
|
||||
int bbReadPixelFast( int x,int y,gxCanvas *buff );
|
||||
void bbWritePixelFast( int x,int y,int argb,gxCanvas *buff );
|
||||
|
||||
|
||||
//2d rendering functions
|
||||
void bbOrigin( int x,int y );
|
||||
void bbViewport( int x,int y,int w,int h );
|
||||
void bbColor( int r,int g,int b );
|
||||
void bbClsColor( int r,int g,int b );
|
||||
void bbCls();
|
||||
void bbPlot( int x,int y );
|
||||
void bbLine( int x1,int y1,int x2,int y2 );
|
||||
void bbRect( int x,int y,int w,int h,int solid );
|
||||
void bbOval( int x,int y,int w,int h,int solid );
|
||||
void bbText( int x,int y,BBStr *str,int centre_x,int centre_y );
|
||||
void bbGetColor( int x,int y );
|
||||
int bbColorRed();
|
||||
int bbColorGreen();
|
||||
int bbColorBlue();
|
||||
|
||||
//font functions
|
||||
gxFont * bbLoadFont( BBStr *name,int height,int bold,int italic,int underline );
|
||||
void bbFreeFont( gxFont *f );
|
||||
void bbSetFont( gxFont *f );
|
||||
int bbFontWidth();
|
||||
int bbFontHeight();
|
||||
int bbStringWidth( BBStr *str );
|
||||
int bbStringHeight( BBStr *str );
|
||||
|
||||
//image functions
|
||||
bbImage* bbLoadImage( BBStr *s );
|
||||
bbImage* bbCopyImage( bbImage *i );
|
||||
bbImage* bbCreateImage( int w,int h,int n );
|
||||
bbImage* bbLoadAnimImage( BBStr *s,int w,int h,int first,int cnt );
|
||||
void bbFreeImage( bbImage *i );
|
||||
int bbSaveImage( bbImage *i,BBStr *filename,int frame );
|
||||
void bbGrabImage( bbImage *i,int x,int y,int n );
|
||||
gxCanvas * bbImageBuffer( bbImage *i,int n );
|
||||
void bbDrawImage( bbImage *i,int x,int y,int frame );
|
||||
void bbDrawBlock( bbImage *i,int x,int y,int frame );
|
||||
void bbTileImage( bbImage *i,int x,int y,int frame );
|
||||
void bbTileBlock( bbImage *i,int x,int y,int frame );
|
||||
void bbDrawImageRect( bbImage *i,int x,int y,int r_x,int r_y,int r_w,int r_h,int frame );
|
||||
void bbDrawBlockRect( bbImage *i,int x,int y,int r_x,int r_y,int r_w,int r_h,int frame );
|
||||
void bbMaskImage( bbImage *i,int r,int g,int b );
|
||||
void bbHandleImage( bbImage *i,int x,int y );
|
||||
void bbScaleImage( bbImage *i,float w,float h );
|
||||
void bbResizeImage( bbImage *i,float w,float h );
|
||||
void bbRotateImage( bbImage *i,float angle );
|
||||
void bbTFormImage( bbImage *i,float a,float b,float c,float d );
|
||||
void bbTFormFilter( int enable );
|
||||
void bbAutoMidHandle( int enable );
|
||||
void bbMidHandle( bbImage *i );
|
||||
int bbImageWidth( bbImage *i );
|
||||
int bbImageHeight( bbImage *i );
|
||||
int bbImageXHandle( bbImage *i );
|
||||
int bbImageYHandle( bbImage *i );
|
||||
int bbImagesOverlap( bbImage *i1,int x1,int y1,bbImage *i2,int x2,int y2 );
|
||||
int bbImagesCollide( bbImage *i1,int x1,int y1,int f1,bbImage *i2,int x2,int y2,int f2 );
|
||||
int bbRectsOverlap( int x1,int y1,int w1,int h1,int x2,int y2,int w2,int h2 );
|
||||
int bbImageRectOverlap( bbImage *i,int x,int y,int r_x,int r_y,int r_w,int r_h );
|
||||
int bbImageRectCollide( bbImage *i,int x,int y,int f,int r_x,int r_y,int r_w,int r_h );
|
||||
|
||||
//simple print functions
|
||||
void bbWrite( BBStr *str );
|
||||
void bbPrint( BBStr *str );
|
||||
BBStr * bbInput( BBStr *prompt );
|
||||
void bbLocate( int x,int y );
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,287 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "bbsys.h"
|
||||
|
||||
gxInput *gx_input;
|
||||
gxDevice *gx_mouse;
|
||||
gxDevice *gx_keyboard;
|
||||
vector<gxDevice*> gx_joysticks;
|
||||
|
||||
static int mouse_x,mouse_y,mouse_z;
|
||||
static const float JLT=-1.0f/3.0f;
|
||||
static const float JHT=1.0f/3.0f;
|
||||
|
||||
bool input_create(){
|
||||
if( gx_input=gx_runtime->openInput( 0 ) ){
|
||||
if( gx_keyboard=gx_input->getKeyboard() ){
|
||||
if( gx_mouse=gx_input->getMouse() ){
|
||||
gx_joysticks.clear();
|
||||
for( int k=0;k<gx_input->numJoysticks();++k ){
|
||||
gx_joysticks.push_back( gx_input->getJoystick(k) );
|
||||
}
|
||||
mouse_x=mouse_y=mouse_z=0;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
gx_runtime->closeInput( gx_input );
|
||||
gx_input=0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool input_destroy(){
|
||||
gx_joysticks.clear();
|
||||
gx_runtime->closeInput( gx_input );
|
||||
gx_input=0;
|
||||
return true;
|
||||
}
|
||||
|
||||
int bbKeyDown( int n ){
|
||||
return gx_keyboard->keyDown( n );
|
||||
}
|
||||
|
||||
int bbKeyHit( int n ){
|
||||
return gx_keyboard->keyHit( n );
|
||||
}
|
||||
|
||||
int bbGetKey(){
|
||||
return gx_input->toAscii( gx_keyboard->getKey() );
|
||||
}
|
||||
|
||||
int bbWaitKey(){
|
||||
for(;;){
|
||||
if( !gx_runtime->idle() ) ThrowRuntimeException( 0 );
|
||||
if( int key=gx_keyboard->getKey( ) ){
|
||||
if( key=gx_input->toAscii( key ) ) return key;
|
||||
}
|
||||
gx_runtime->delay( 20 );
|
||||
}
|
||||
}
|
||||
|
||||
void bbFlushKeys(){
|
||||
gx_keyboard->flush();
|
||||
}
|
||||
|
||||
int bbMouseDown( int n ){
|
||||
return gx_mouse->keyDown( n );
|
||||
}
|
||||
|
||||
int bbMouseHit( int n ){
|
||||
return gx_mouse->keyHit( n );
|
||||
}
|
||||
|
||||
int bbGetMouse(){
|
||||
return gx_mouse->getKey();
|
||||
}
|
||||
|
||||
int bbWaitMouse(){
|
||||
for(;;){
|
||||
if( !gx_runtime->idle() ) ThrowRuntimeException( 0 );
|
||||
if( int key=gx_mouse->getKey() ) return key;
|
||||
gx_runtime->delay( 20 );
|
||||
}
|
||||
}
|
||||
|
||||
int bbMouseWait(){
|
||||
return bbWaitMouse();
|
||||
}
|
||||
|
||||
int bbMouseX(){
|
||||
return gx_mouse->getAxisState( 0 );
|
||||
}
|
||||
|
||||
int bbMouseY(){
|
||||
return gx_mouse->getAxisState( 1 );
|
||||
}
|
||||
|
||||
int bbMouseZ(){
|
||||
return gx_mouse->getAxisState( 2 )/120;
|
||||
}
|
||||
|
||||
int bbMouseXSpeed(){
|
||||
int dx=bbMouseX()-mouse_x;
|
||||
mouse_x+=dx;
|
||||
return dx;
|
||||
}
|
||||
|
||||
int bbMouseYSpeed(){
|
||||
int dy=bbMouseY()-mouse_y;
|
||||
mouse_y+=dy;
|
||||
return dy;
|
||||
}
|
||||
|
||||
int bbMouseZSpeed(){
|
||||
int dz=bbMouseZ()-mouse_z;
|
||||
mouse_z+=dz;
|
||||
return dz;
|
||||
}
|
||||
|
||||
void bbFlushMouse(){
|
||||
gx_mouse->flush();
|
||||
}
|
||||
|
||||
void bbMoveMouse( int x,int y ){
|
||||
gx_input->moveMouse( mouse_x=x,mouse_y=y );
|
||||
}
|
||||
|
||||
int bbJoyType( int port ){
|
||||
return gx_input->getJoystickType( port );
|
||||
}
|
||||
|
||||
int bbJoyDown( int n,int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
return gx_joysticks[port]->keyDown( n );
|
||||
}
|
||||
|
||||
int bbJoyHit( int n,int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
return gx_joysticks[port]->keyHit( n );
|
||||
}
|
||||
|
||||
int bbGetJoy( int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
return gx_joysticks[port]->getKey();
|
||||
}
|
||||
|
||||
int bbWaitJoy( int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
for(;;){
|
||||
if( !gx_runtime->idle() ) ThrowRuntimeException( 0 );
|
||||
if( int key=gx_joysticks[port]->getKey() ) return key;
|
||||
gx_runtime->delay( 20 );
|
||||
}
|
||||
}
|
||||
|
||||
float bbJoyX( int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
return gx_joysticks[port]->getAxisState(0);
|
||||
}
|
||||
|
||||
float bbJoyY( int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
return gx_joysticks[port]->getAxisState(1);
|
||||
}
|
||||
|
||||
float bbJoyZ( int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
return gx_joysticks[port]->getAxisState(2);
|
||||
}
|
||||
|
||||
float bbJoyU( int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
return gx_joysticks[port]->getAxisState(3);
|
||||
}
|
||||
|
||||
float bbJoyV( int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
return gx_joysticks[port]->getAxisState(4);
|
||||
}
|
||||
|
||||
float bbJoyPitch( int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
return gx_joysticks[port]->getAxisState(5)*180;
|
||||
}
|
||||
|
||||
float bbJoyYaw( int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
return gx_joysticks[port]->getAxisState(6)*180;
|
||||
}
|
||||
|
||||
float bbJoyRoll( int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
return gx_joysticks[port]->getAxisState(7)*180;
|
||||
}
|
||||
|
||||
int bbJoyHat( int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
return gx_joysticks[port]->getAxisState(8);
|
||||
}
|
||||
|
||||
int bbJoyXDir( int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
float t=gx_joysticks[port]->getAxisState(0);
|
||||
return t<JLT ? -1 : ( t>JHT ? 1 : 0 );
|
||||
}
|
||||
|
||||
int bbJoyYDir( int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
float t=gx_joysticks[port]->getAxisState(1);
|
||||
return t<JLT ? -1 : ( t>JHT ? 1 : 0 );
|
||||
}
|
||||
|
||||
int bbJoyZDir( int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
float t=gx_joysticks[port]->getAxisState(2);
|
||||
return t<JLT ? -1 : ( t>JHT ? 1 : 0 );
|
||||
}
|
||||
|
||||
int bbJoyUDir( int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
float t=gx_joysticks[port]->getAxisState(3);
|
||||
return t<JLT ? -1 : ( t>JHT ? 1 : 0 );
|
||||
}
|
||||
|
||||
int bbJoyVDir( int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
float t=gx_joysticks[port]->getAxisState(4);
|
||||
return t<JLT ? -1 : ( t>JHT ? 1 : 0 );
|
||||
}
|
||||
|
||||
void bbFlushJoy(){
|
||||
for( int k=0;k<gx_joysticks.size();++k ) gx_joysticks[k]->flush();
|
||||
}
|
||||
|
||||
void bbEnableDirectInput( int enable ){
|
||||
gx_runtime->enableDirectInput( !!enable );
|
||||
}
|
||||
|
||||
int bbDirectInputEnabled(){
|
||||
return gx_runtime->directInputEnabled();
|
||||
}
|
||||
|
||||
void input_link( void (*rtSym)( const char *sym,void *pc ) ){
|
||||
rtSym( "%KeyDown%key",bbKeyDown );
|
||||
rtSym( "%KeyHit%key",bbKeyHit );
|
||||
rtSym( "%GetKey",bbGetKey );
|
||||
rtSym( "%WaitKey",bbWaitKey );
|
||||
rtSym( "FlushKeys",bbFlushKeys );
|
||||
|
||||
rtSym( "%MouseDown%button",bbMouseDown );
|
||||
rtSym( "%MouseHit%button",bbMouseHit );
|
||||
rtSym( "%GetMouse",bbGetMouse );
|
||||
rtSym( "%WaitMouse",bbWaitMouse );
|
||||
rtSym( "%MouseWait",bbWaitMouse );
|
||||
rtSym( "%MouseX",bbMouseX );
|
||||
rtSym( "%MouseY",bbMouseY );
|
||||
rtSym( "%MouseZ",bbMouseZ );
|
||||
rtSym( "%MouseXSpeed",bbMouseXSpeed );
|
||||
rtSym( "%MouseYSpeed",bbMouseYSpeed );
|
||||
rtSym( "%MouseZSpeed",bbMouseZSpeed );
|
||||
rtSym( "FlushMouse",bbFlushMouse );
|
||||
rtSym( "MoveMouse%x%y",bbMoveMouse );
|
||||
|
||||
rtSym( "%JoyType%port=0",bbJoyType );
|
||||
rtSym( "%JoyDown%button%port=0",bbJoyDown );
|
||||
rtSym( "%JoyHit%button%port=0",bbJoyHit );
|
||||
rtSym( "%GetJoy%port=0",bbGetJoy );
|
||||
rtSym( "%WaitJoy%port=0",bbWaitJoy );
|
||||
rtSym( "%JoyWait%port=0",bbWaitJoy );
|
||||
rtSym( "#JoyX%port=0",bbJoyX );
|
||||
rtSym( "#JoyY%port=0",bbJoyY );
|
||||
rtSym( "#JoyZ%port=0",bbJoyZ );
|
||||
rtSym( "#JoyU%port=0",bbJoyU );
|
||||
rtSym( "#JoyV%port=0",bbJoyV );
|
||||
rtSym( "#JoyPitch%port=0",bbJoyPitch );
|
||||
rtSym( "#JoyYaw%port=0",bbJoyYaw );
|
||||
rtSym( "#JoyRoll%port=0",bbJoyRoll );
|
||||
rtSym( "%JoyHat%port=0",bbJoyHat );
|
||||
rtSym( "%JoyXDir%port=0",bbJoyXDir );
|
||||
rtSym( "%JoyYDir%port=0",bbJoyYDir );
|
||||
rtSym( "%JoyZDir%port=0",bbJoyZDir );
|
||||
rtSym( "%JoyUDir%port=0",bbJoyUDir );
|
||||
rtSym( "%JoyVDir%port=0",bbJoyVDir );
|
||||
rtSym( "FlushJoy",bbFlushJoy );
|
||||
|
||||
rtSym( "EnableDirectInput%enable",bbEnableDirectInput );
|
||||
rtSym( "%DirectInputEnabled",bbDirectInputEnabled );
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
|
||||
#ifndef BBINPUT_H
|
||||
#define BBINPUT_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "bbsys.h"
|
||||
#include "../gxruntime/gxinput.h"
|
||||
|
||||
extern gxInput *gx_input;
|
||||
extern gxDevice *gx_mouse;
|
||||
extern gxDevice *gx_keyboard;
|
||||
extern std::vector<gxDevice*> gx_joysticks;
|
||||
|
||||
//keyboard
|
||||
int bbKeyDown( int n );
|
||||
int bbKeyHit( int n );
|
||||
int bbGetKey();
|
||||
int bbWaitKey();
|
||||
void bbFlushKeys();
|
||||
|
||||
//mouse
|
||||
int bbMouseDown( int n );
|
||||
int bbMouseHit( int n );
|
||||
int bbGetMouse();
|
||||
int bbWaitMouse();
|
||||
int bbMouseX();
|
||||
int bbMouseY();
|
||||
int bbMouseXSpeed();
|
||||
int bbMouseYSpeed();
|
||||
void bbMoveMouse( int x,int y );
|
||||
void bbFlushMouse();
|
||||
|
||||
//joysticks
|
||||
int bbJoyType( int port );
|
||||
int bbJoyDown( int n,int port );
|
||||
int bbJoyHit( int n,int port );
|
||||
int bbGetJoy( int port );
|
||||
int bbWaitJoy( int port );
|
||||
float bbJoyX( int port );
|
||||
float bbJoyY( int port );
|
||||
float bbJoyZ( int port );
|
||||
float bbJoyU( int port );
|
||||
float bbJoyV( int port );
|
||||
float bbJoyPitch( int port );
|
||||
float bbJoyYaw( int port );
|
||||
float bbJoyRoll( int port );
|
||||
int bbJoyXDir( int port );
|
||||
int bbJoyYDir( int port );
|
||||
int bbJoyZDir( int port );
|
||||
int bbJoyUDir( int port );
|
||||
int bbJoyVDir( int port );
|
||||
void bbFlushJoy();
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,80 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "bbmath.h"
|
||||
|
||||
static int rnd_state;
|
||||
static const int RND_A=48271;
|
||||
static const int RND_M=2147483647;
|
||||
static const int RND_Q=44488;
|
||||
static const int RND_R=3399;
|
||||
|
||||
static const float dtor=0.0174532925199432957692369076848861f;
|
||||
static const float rtod=57.2957795130823208767981548141052f;
|
||||
|
||||
float bbSin( float n ){ return (float)sin(n*dtor); }
|
||||
float bbCos( float n ){ return (float)cos(n*dtor); }
|
||||
float bbTan( float n ){ return (float)tan(n*dtor); }
|
||||
float bbASin( float n ){ return (float)asin(n)*rtod; }
|
||||
float bbACos( float n ){ return (float)acos(n)*rtod; }
|
||||
float bbATan( float n ){ return (float)atan(n)*rtod; }
|
||||
float bbATan2( float n,float t ){ return (float)atan2(n,t)*rtod; }
|
||||
float bbSqr( float n ){ return (float)sqrt(n); }
|
||||
float bbFloor( float n ){ return (float)floor(n); }
|
||||
float bbCeil( float n ){ return (float)ceil(n); }
|
||||
float bbExp( float n ){ return (float)exp(n); }
|
||||
float bbLog( float n ){ return (float)log(n); }
|
||||
float bbLog10( float n ){ return (float)log10(n); }
|
||||
|
||||
//return rand float from 0...1
|
||||
static inline float rnd(){
|
||||
rnd_state=RND_A*(rnd_state%RND_Q)-RND_R*(rnd_state/RND_Q);
|
||||
if( rnd_state<0 ) rnd_state+=RND_M;
|
||||
return (rnd_state&65535)/65536.0f+(.5f/65536.0f);
|
||||
}
|
||||
|
||||
float bbRnd( float from,float to ){
|
||||
return rnd()*(to-from)+from;
|
||||
}
|
||||
|
||||
int bbRand( int from,int to ){
|
||||
if( to<from ) std::swap( from,to );
|
||||
return int(rnd()*(to-from+1))+from;
|
||||
}
|
||||
|
||||
void bbSeedRnd( int seed ){
|
||||
seed&=0x7fffffff;
|
||||
rnd_state=seed ? seed : 1;
|
||||
}
|
||||
|
||||
int bbRndSeed(){
|
||||
return rnd_state;
|
||||
}
|
||||
|
||||
bool math_create(){
|
||||
bbSeedRnd( 0x1234 );
|
||||
return true;
|
||||
}
|
||||
|
||||
bool math_destroy(){
|
||||
return true;
|
||||
}
|
||||
|
||||
void math_link( void (*rtSym)( const char *sym,void *pc ) ){
|
||||
rtSym( "#Sin#degrees",bbSin );
|
||||
rtSym( "#Cos#degrees",bbCos );
|
||||
rtSym( "#Tan#degrees",bbTan );
|
||||
rtSym( "#ASin#float",bbASin );
|
||||
rtSym( "#ACos#float",bbACos );
|
||||
rtSym( "#ATan#float",bbATan );
|
||||
rtSym( "#ATan2#floata#floatb",bbATan2 );
|
||||
rtSym( "#Sqr#float",bbSqr );
|
||||
rtSym( "#Floor#float",bbFloor );
|
||||
rtSym( "#Ceil#float",bbCeil );
|
||||
rtSym( "#Exp#float",bbExp );
|
||||
rtSym( "#Log#float",bbLog );
|
||||
rtSym( "#Log10#float",bbLog10 );
|
||||
rtSym( "#Rnd#from#to=0",bbRnd );
|
||||
rtSym( "%Rand%from%to=1",bbRand );
|
||||
rtSym( "SeedRnd%seed",bbSeedRnd );
|
||||
rtSym( "%RndSeed",bbRndSeed );
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
|
||||
#ifndef BBMATH_H
|
||||
#define BBMATH_H
|
||||
|
||||
float bbSin( float n );
|
||||
float bbCos( float n );
|
||||
float bbTan( float n );
|
||||
float bbASin( float n );
|
||||
float bbACos( float n );
|
||||
float bbATan( float n );
|
||||
float bbHSin( float n );
|
||||
float bbHCos( float n );
|
||||
float bbHTan( float n );
|
||||
float bbATan2( float n,float t );
|
||||
float bbSqr( float n );
|
||||
float bbFloor( float n );
|
||||
float bbCeil( float n );
|
||||
float bbExp( float n );
|
||||
float bbLog( float n );
|
||||
float bbLog10( float n );
|
||||
float bbRnd( float from,float to );
|
||||
void bbSeedRnd( int seed );
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,260 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "bbsys.h"
|
||||
#include "bbruntime.h"
|
||||
|
||||
void bbEnd() {
|
||||
ThrowRuntimeException(0);
|
||||
}
|
||||
void bbStop() {
|
||||
gx_runtime->debugStop();
|
||||
if (!gx_runtime->idle()) ThrowRuntimeException(0);
|
||||
}
|
||||
|
||||
void bbAppTitle(BBStr *ti, BBStr *cp) {
|
||||
gx_runtime->setTitle(*ti, *cp);
|
||||
delete ti; delete cp;
|
||||
}
|
||||
|
||||
void bbRuntimeError(BBStr *str) {
|
||||
string t = *str; delete str;
|
||||
if (t.size() > 255) t[255] = 0;
|
||||
static char err[256];
|
||||
strcpy(err, t.c_str());
|
||||
ThrowRuntimeException(err);
|
||||
}
|
||||
|
||||
int bbExecFile(BBStr *f) {
|
||||
string t = *f; delete f;
|
||||
int n = gx_runtime->execute(t);
|
||||
if (!gx_runtime->idle()) ThrowRuntimeException(0);
|
||||
return n;
|
||||
}
|
||||
|
||||
void bbDelay(int ms) {
|
||||
if (!gx_runtime->delay(ms)) ThrowRuntimeException(0);
|
||||
}
|
||||
|
||||
int bbMilliSecs() {
|
||||
return gx_runtime->getMilliSecs();
|
||||
}
|
||||
|
||||
BBStr * bbCommandLine() {
|
||||
return d_new BBStr(gx_runtime->commandLine());
|
||||
}
|
||||
|
||||
BBStr * bbSystemProperty(BBStr *p) {
|
||||
string t = gx_runtime->systemProperty(*p);
|
||||
delete p; return d_new BBStr(t);
|
||||
}
|
||||
|
||||
BBStr * bbGetEnv(BBStr *env_var) {
|
||||
char *p = getenv(env_var->c_str());
|
||||
BBStr *val = d_new BBStr(p ? p : "");
|
||||
delete env_var;
|
||||
return val;
|
||||
}
|
||||
|
||||
void bbSetEnv(BBStr *env_var, BBStr *val) {
|
||||
string t = *env_var + "=" + *val;
|
||||
_putenv(t.c_str());
|
||||
delete env_var;
|
||||
delete val;
|
||||
}
|
||||
|
||||
gxTimer * bbCreateTimer(int hertz) {
|
||||
gxTimer *t = gx_runtime->createTimer(hertz);
|
||||
return t;
|
||||
}
|
||||
|
||||
int bbWaitTimer(gxTimer *t) {
|
||||
int n = t->wait();
|
||||
if (!gx_runtime->idle()) ThrowRuntimeException(0);
|
||||
return n;
|
||||
}
|
||||
|
||||
void bbFreeTimer(gxTimer *t) {
|
||||
gx_runtime->freeTimer(t);
|
||||
}
|
||||
|
||||
void bbDebugLog(BBStr *t) {
|
||||
gx_runtime->debugLog(t->c_str());
|
||||
delete t;
|
||||
}
|
||||
|
||||
void _bbDebugStmt(int pos, const char *file) {
|
||||
gx_runtime->debugStmt(pos, file);
|
||||
if (!gx_runtime->idle()) ThrowRuntimeException(0);
|
||||
}
|
||||
|
||||
void _bbDebugEnter(void *frame, void *env, const char *func) {
|
||||
gx_runtime->debugEnter(frame, env, func);
|
||||
}
|
||||
|
||||
void _bbDebugLeave() {
|
||||
gx_runtime->debugLeave();
|
||||
}
|
||||
|
||||
bool basic_create();
|
||||
bool basic_destroy();
|
||||
void basic_link(void(*rtSym)(const char *sym, void *pc));
|
||||
bool math_create();
|
||||
bool math_destroy();
|
||||
void math_link(void(*rtSym)(const char *sym, void *pc));
|
||||
bool string_create();
|
||||
bool string_destroy();
|
||||
void string_link(void(*rtSym)(const char *sym, void *pc));
|
||||
bool stream_create();
|
||||
bool stream_destroy();
|
||||
void stream_link(void(*rtSym)(const char *sym, void *pc));
|
||||
bool sockets_create();
|
||||
bool sockets_destroy();
|
||||
void sockets_link(void(*rtSym)(const char *sym, void *pc));
|
||||
bool filesystem_create();
|
||||
bool filesystem_destroy();
|
||||
void filesystem_link(void(*rtSym)(const char *sym, void *pc));
|
||||
bool bank_create();
|
||||
bool bank_destroy();
|
||||
void bank_link(void(*rtSym)(const char *sym, void *pc));
|
||||
bool graphics_create();
|
||||
bool graphics_destroy();
|
||||
void graphics_link(void(*rtSym)(const char *sym, void *pc));
|
||||
bool input_create();
|
||||
bool input_destroy();
|
||||
void input_link(void(*rtSym)(const char *sym, void *pc));
|
||||
bool audio_create();
|
||||
bool audio_destroy();
|
||||
void audio_link(void(*rtSym)(const char *sym, void *pc));
|
||||
//bool multiplay_create();
|
||||
//bool multiplay_destroy();
|
||||
//void multiplay_link( void (*rtSym)( const char *sym,void *pc ) );
|
||||
bool userlibs_create();
|
||||
void userlibs_destroy();
|
||||
void userlibs_link(void(*rtSym)(const char *sym, void *pc));
|
||||
bool blitz3d_create();
|
||||
bool blitz3d_destroy();
|
||||
void blitz3d_link(void(*rtSym)(const char *sym, void *pc));
|
||||
|
||||
void bbruntime_link(void(*rtSym)(const char *sym, void *pc)) {
|
||||
|
||||
rtSym("End", bbEnd);
|
||||
rtSym("Stop", bbStop);
|
||||
rtSym("AppTitle$title$close_prompt=\"\"", bbAppTitle);
|
||||
rtSym("RuntimeError$message", bbRuntimeError);
|
||||
rtSym("ExecFile$command", bbExecFile);
|
||||
rtSym("Delay%millisecs", bbDelay);
|
||||
rtSym("%MilliSecs", bbMilliSecs);
|
||||
rtSym("$CommandLine", bbCommandLine);
|
||||
rtSym("$SystemProperty$property", bbSystemProperty);
|
||||
rtSym("$GetEnv$env_var", bbGetEnv);
|
||||
rtSym("SetEnv$env_var$value", bbSetEnv);
|
||||
|
||||
rtSym("%CreateTimer%hertz", bbCreateTimer);
|
||||
rtSym("%WaitTimer%timer", bbWaitTimer);
|
||||
rtSym("FreeTimer%timer", bbFreeTimer);
|
||||
rtSym("DebugLog$text", bbDebugLog);
|
||||
|
||||
rtSym("_bbDebugStmt", _bbDebugStmt);
|
||||
rtSym("_bbDebugEnter", _bbDebugEnter);
|
||||
rtSym("_bbDebugLeave", _bbDebugLeave);
|
||||
|
||||
basic_link(rtSym);
|
||||
math_link(rtSym);
|
||||
string_link(rtSym);
|
||||
stream_link(rtSym);
|
||||
sockets_link(rtSym);
|
||||
filesystem_link(rtSym);
|
||||
bank_link(rtSym);
|
||||
graphics_link(rtSym);
|
||||
input_link(rtSym);
|
||||
audio_link(rtSym);
|
||||
//multiplay_link( rtSym );
|
||||
blitz3d_link(rtSym);
|
||||
userlibs_link(rtSym);
|
||||
}
|
||||
|
||||
//start up error
|
||||
static void sue(const char *t) {
|
||||
string p = string("Startup Error: ") + t;
|
||||
gx_runtime->debugInfo(p.c_str());
|
||||
}
|
||||
|
||||
bool bbruntime_create() {
|
||||
if (basic_create()) {
|
||||
if (math_create()) {
|
||||
if (string_create()) {
|
||||
if (stream_create()) {
|
||||
if (sockets_create()) {
|
||||
if (filesystem_create()) {
|
||||
if (bank_create()) {
|
||||
if (graphics_create()) {
|
||||
if (input_create()) {
|
||||
if (audio_create()) {
|
||||
//if( multiplay_create() ){
|
||||
if (blitz3d_create()) {
|
||||
if (userlibs_create()) {
|
||||
return true;
|
||||
}
|
||||
} else sue("blitz3d_create failed");
|
||||
// multiplay_destroy();
|
||||
//}else sue( "multiplay_create failed" );
|
||||
audio_destroy();
|
||||
} else sue("audio_create failed");
|
||||
input_destroy();
|
||||
} else sue("input_create failed");
|
||||
graphics_destroy();
|
||||
} else sue("graphics_create failed");
|
||||
bank_destroy();
|
||||
} else sue("bank_create failed");
|
||||
filesystem_destroy();
|
||||
} else sue("filesystem_create failed");
|
||||
sockets_destroy();
|
||||
} else sue("sockets_create failed");
|
||||
stream_destroy();
|
||||
} else sue("stream_create failed");
|
||||
string_destroy();
|
||||
} else sue("string_create failed");
|
||||
math_destroy();
|
||||
} else sue("math_create failed");
|
||||
basic_destroy();
|
||||
} else sue("basic_create failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool bbruntime_destroy() {
|
||||
userlibs_destroy();
|
||||
blitz3d_destroy();
|
||||
//multiplay_destroy();
|
||||
audio_destroy();
|
||||
input_destroy();
|
||||
graphics_destroy();
|
||||
bank_destroy();
|
||||
filesystem_destroy();
|
||||
sockets_destroy();
|
||||
stream_destroy();
|
||||
string_destroy();
|
||||
math_destroy();
|
||||
basic_destroy();
|
||||
return true;
|
||||
}
|
||||
|
||||
const char *bbruntime_run(gxRuntime *rt, void(*pc)(), bool dbg) {
|
||||
debug = dbg;
|
||||
gx_runtime = rt;
|
||||
|
||||
if (!bbruntime_create()) return "Unable to start program";
|
||||
const char *t = 0;
|
||||
try {
|
||||
if (!gx_runtime->idle()) ThrowRuntimeException(0);
|
||||
pc();
|
||||
gx_runtime->debugInfo("Program has ended");
|
||||
} catch (bbEx x) {
|
||||
t = x.err;
|
||||
}
|
||||
bbruntime_destroy();
|
||||
return t;
|
||||
}
|
||||
|
||||
void bbruntime_panic(const char *err) {
|
||||
ThrowRuntimeException(err);
|
||||
}
|
||||
@@ -0,0 +1,317 @@
|
||||
# Microsoft Developer Studio Project File - Name="bbruntime" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Static Library" 0x0104
|
||||
|
||||
CFG=bbruntime - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "bbruntime.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "bbruntime.mak" CFG="bbruntime - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "bbruntime - Win32 Release" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE "bbruntime - Win32 Debug" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE "bbruntime - Win32 Blitz3DRelease" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE "bbruntime - Win32 Blitz2DRelease" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "bbruntime - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||
# ADD CPP /nologo /MT /W3 /GX /Ox /Ow /Og /Oi /Os /Ob2 /Gf /Gy /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /Yu"std.h" /FD /c
|
||||
# SUBTRACT CPP /Ot
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
!ELSEIF "$(CFG)" == "bbruntime - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /Yu"std.h" /FD /GZ /c
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
!ELSEIF "$(CFG)" == "bbruntime - Win32 Blitz3DRelease"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "bbruntime___Win32_Blitz3DRelease"
|
||||
# PROP BASE Intermediate_Dir "bbruntime___Win32_Blitz3DRelease"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "bbruntime___Win32_Blitz3DRelease"
|
||||
# PROP Intermediate_Dir "bbruntime___Win32_Blitz3DRelease"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /Ox /Ow /Og /Oi /Os /Ob2 /Gf /Gy /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /Yu"std.h" /FD /c
|
||||
# SUBTRACT BASE CPP /Ot
|
||||
# ADD CPP /nologo /G6 /Gz /MT /W3 /GX /O2 /Ob2 /D "_LIB" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "PRO" /FD /c
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
!ELSEIF "$(CFG)" == "bbruntime - Win32 Blitz2DRelease"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "bbruntime___Win32_Blitz2DRelease"
|
||||
# PROP BASE Intermediate_Dir "bbruntime___Win32_Blitz2DRelease"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "bbruntime___Win32_Blitz2DRelease"
|
||||
# PROP Intermediate_Dir "bbruntime___Win32_Blitz2DRelease"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /Ox /Ow /Og /Oi /Os /Ob2 /Gf /Gy /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /Yu"std.h" /FD /c
|
||||
# SUBTRACT BASE CPP /Ot
|
||||
# ADD CPP /nologo /G6 /MT /W3 /GX /O2 /Ob2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /Yu"std.h" /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "bbruntime - Win32 Release"
|
||||
# Name "bbruntime - Win32 Debug"
|
||||
# Name "bbruntime - Win32 Blitz3DRelease"
|
||||
# Name "bbruntime - Win32 Blitz2DRelease"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\basic.cpp
|
||||
|
||||
!IF "$(CFG)" == "bbruntime - Win32 Release"
|
||||
|
||||
!ELSEIF "$(CFG)" == "bbruntime - Win32 Debug"
|
||||
|
||||
# ADD CPP /Yu
|
||||
|
||||
!ELSEIF "$(CFG)" == "bbruntime - Win32 Blitz3DRelease"
|
||||
|
||||
!ELSEIF "$(CFG)" == "bbruntime - Win32 Blitz2DRelease"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbaudio.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbbank.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbblitz3d.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbfilesystem.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbgraphics.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbinput.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbmath.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbruntime.cpp
|
||||
|
||||
!IF "$(CFG)" == "bbruntime - Win32 Release"
|
||||
|
||||
!ELSEIF "$(CFG)" == "bbruntime - Win32 Debug"
|
||||
|
||||
# ADD CPP /Yu"std.h"
|
||||
|
||||
!ELSEIF "$(CFG)" == "bbruntime - Win32 Blitz3DRelease"
|
||||
|
||||
!ELSEIF "$(CFG)" == "bbruntime - Win32 Blitz2DRelease"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbsockets.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbstream.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbstring.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbsys.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\multiplay.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\multiplay_setup.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\multiplay_setup.rc
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\std.cpp
|
||||
# ADD CPP /Yc"std.h"
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\userlibs.cpp
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\basic.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbaudio.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbbank.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbblitz3d.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbfilesystem.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbgraphics.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbinput.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbmath.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbruntime.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbsockets.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbstream.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbstring.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbsys.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\multiplay.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\multiplay_setup.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\resource.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\std.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\userlibs.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
||||
@@ -0,0 +1,21 @@
|
||||
|
||||
/*
|
||||
|
||||
Platform neutral runtime library.
|
||||
|
||||
To be statically linked with an appropriate gxruntime driver.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef BBRUNTIME_H
|
||||
#define BBRUNTIME_H
|
||||
|
||||
#include "../gxruntime/gxruntime.h"
|
||||
|
||||
void bbruntime_link( void (*rtSym)( const char *sym,void *pc ) );
|
||||
|
||||
const char *bbruntime_run( gxRuntime *runtime,void (*pc)(),bool debug );
|
||||
|
||||
void bbruntime_panic( const char *err );
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,191 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<SccProjectName />
|
||||
<SccLocalPath />
|
||||
<ProjectGuid>{DF8CAA9D-7154-4D5F-BCCC-0D7BB57C7354}</ProjectGuid>
|
||||
<ProjectName>RuntimeLib</ProjectName>
|
||||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<UseOfMfc>false</UseOfMfc>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<UseOfMfc>false</UseOfMfc>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="$(VCTargetsPath)Microsoft.Cpp.UpgradeFromVC60.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="$(VCTargetsPath)Microsoft.Cpp.UpgradeFromVC60.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<OutDir>..\#Build\$(ProjectName)\$(ConfigurationName)\</OutDir>
|
||||
<IntDir>..\#Intermediate\$(ProjectName)\$(ConfigurationName)\</IntDir>
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<IncludePath>$(DXSDK_DIR)Include\;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
|
||||
<LibraryPath>$(DXSDK_DIR)Lib\x86\;$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(NETFXKitsDir)Lib\um\x86</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<OutDir>..\#Build\$(ProjectName)\$(ConfigurationName)\</OutDir>
|
||||
<IntDir>..\#Intermediate\$(ProjectName)\$(ConfigurationName)\</IntDir>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<IncludePath>$(DXSDK_DIR)Include\;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
|
||||
<LibraryPath>$(DXSDK_DIR)Lib\x86\;$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(NETFXKitsDir)Lib\um\x86</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<InlineFunctionExpansion>Default</InlineFunctionExpansion>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<StringPooling>true</StringPooling>
|
||||
<FloatingPointExceptions>true</FloatingPointExceptions>
|
||||
<CreateHotpatchableImage>true</CreateHotpatchableImage>
|
||||
<CompileAsManaged>false</CompileAsManaged>
|
||||
<CompileAsWinRT>false</CompileAsWinRT>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PrecompiledHeaderFile />
|
||||
<ControlFlowGuard>Guard</ControlFlowGuard>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<ProgramDataBaseFileName>$(IntDir)vc$(PlatformToolsetVersion).pdb</ProgramDataBaseFileName>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
||||
<EnforceTypeConversionRules>true</EnforceTypeConversionRules>
|
||||
<RuntimeTypeInfo>true</RuntimeTypeInfo>
|
||||
<OpenMPSupport>false</OpenMPSupport>
|
||||
<CallingConvention>StdCall</CallingConvention>
|
||||
</ClCompile>
|
||||
<ResourceCompile>
|
||||
<Culture>0x0409</Culture>
|
||||
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ResourceCompile>
|
||||
<Bscmake>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<OutputFile>.\Debug\bbruntime.bsc</OutputFile>
|
||||
</Bscmake>
|
||||
<Lib>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<TargetMachine>MachineX86</TargetMachine>
|
||||
</Lib>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
||||
<StringPooling>true</StringPooling>
|
||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<FloatingPointExceptions>true</FloatingPointExceptions>
|
||||
<CreateHotpatchableImage>true</CreateHotpatchableImage>
|
||||
<CompileAsManaged>false</CompileAsManaged>
|
||||
<CompileAsWinRT>false</CompileAsWinRT>
|
||||
<SDLCheck>false</SDLCheck>
|
||||
<PrecompiledHeaderFile />
|
||||
<ControlFlowGuard>Guard</ControlFlowGuard>
|
||||
<ProgramDataBaseFileName>$(IntDir)vc$(PlatformToolsetVersion).pdb</ProgramDataBaseFileName>
|
||||
<EnforceTypeConversionRules>false</EnforceTypeConversionRules>
|
||||
<RuntimeTypeInfo>false</RuntimeTypeInfo>
|
||||
<OpenMPSupport>false</OpenMPSupport>
|
||||
<CallingConvention>StdCall</CallingConvention>
|
||||
</ClCompile>
|
||||
<ResourceCompile>
|
||||
<Culture>0x0409</Culture>
|
||||
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ResourceCompile>
|
||||
<Bscmake>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<OutputFile>.\Release\bbruntime.bsc</OutputFile>
|
||||
</Bscmake>
|
||||
<Lib>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<TargetMachine>MachineX86</TargetMachine>
|
||||
</Lib>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="basic.cpp" />
|
||||
<ClCompile Include="bbaudio.cpp" />
|
||||
<ClCompile Include="bbbank.cpp" />
|
||||
<ClCompile Include="bbblitz3d.cpp" />
|
||||
<ClCompile Include="bbfilesystem.cpp" />
|
||||
<ClCompile Include="bbgraphics.cpp" />
|
||||
<ClCompile Include="bbinput.cpp" />
|
||||
<ClCompile Include="bbmath.cpp" />
|
||||
<ClCompile Include="bbruntime.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">std.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
<ClCompile Include="bbsockets.cpp" />
|
||||
<ClCompile Include="bbstream.cpp" />
|
||||
<ClCompile Include="bbstring.cpp" />
|
||||
<ClCompile Include="bbsys.cpp" />
|
||||
<ClCompile Include="multiplay.cpp" />
|
||||
<ClCompile Include="multiplay_setup.cpp" />
|
||||
<ClCompile Include="std.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">std.h</PrecompiledHeaderFile>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">std.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
<ClCompile Include="userlibs.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="multiplay_setup.rc" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="basic.h" />
|
||||
<ClInclude Include="bbaudio.h" />
|
||||
<ClInclude Include="bbbank.h" />
|
||||
<ClInclude Include="bbblitz3d.h" />
|
||||
<ClInclude Include="bbfilesystem.h" />
|
||||
<ClInclude Include="bbgraphics.h" />
|
||||
<ClInclude Include="bbinput.h" />
|
||||
<ClInclude Include="bbmath.h" />
|
||||
<ClInclude Include="bbruntime.h" />
|
||||
<ClInclude Include="bbsockets.h" />
|
||||
<ClInclude Include="bbstream.h" />
|
||||
<ClInclude Include="bbstring.h" />
|
||||
<ClInclude Include="bbsys.h" />
|
||||
<ClInclude Include="multiplay.h" />
|
||||
<ClInclude Include="multiplay_setup.h" />
|
||||
<ClInclude Include="resource.h" />
|
||||
<ClInclude Include="std.h" />
|
||||
<ClInclude Include="userlibs.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,127 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{2be14919-a9d3-4029-97d0-c02d529d1a8e}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cxx;rc;def;r;odl;idl;hpj;bat</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{2a5eb825-a520-433a-88ff-a2f0408189ac}</UniqueIdentifier>
|
||||
<Extensions>h;hpp;hxx;hm;inl</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="basic.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="bbaudio.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="bbbank.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="bbblitz3d.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="bbfilesystem.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="bbgraphics.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="bbinput.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="bbmath.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="bbruntime.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="bbsockets.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="bbstream.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="bbstring.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="bbsys.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="multiplay.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="multiplay_setup.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="std.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="userlibs.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="multiplay_setup.rc">
|
||||
<Filter>Source Files</Filter>
|
||||
</ResourceCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="basic.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="bbaudio.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="bbbank.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="bbblitz3d.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="bbfilesystem.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="bbgraphics.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="bbinput.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="bbmath.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="bbruntime.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="bbsockets.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="bbstream.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="bbstring.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="bbsys.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="multiplay.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="multiplay_setup.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="resource.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="std.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="userlibs.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,505 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "bbsockets.h"
|
||||
|
||||
static bool socks_ok;
|
||||
static WSADATA wsadata;
|
||||
static int recv_timeout;
|
||||
static int read_timeout;
|
||||
static int accept_timeout;
|
||||
|
||||
static void close(SOCKET sock, int e) {
|
||||
if (e < 0) {
|
||||
int opt = 1;
|
||||
setsockopt(sock, SOL_SOCKET, SO_DONTLINGER, (char*)&opt, sizeof(opt));
|
||||
}
|
||||
closesocket(sock);
|
||||
}
|
||||
|
||||
class UDPStream;
|
||||
class TCPStream;
|
||||
class TCPServer;
|
||||
|
||||
static set<UDPStream*> udp_set;
|
||||
static set<TCPStream*> tcp_set;
|
||||
static set<TCPServer*> server_set;
|
||||
|
||||
class UDPStream : public bbStream {
|
||||
public:
|
||||
UDPStream(SOCKET s);
|
||||
~UDPStream();
|
||||
|
||||
int read(char *buff, int size);
|
||||
int write(const char *buff, int size);
|
||||
int avail();
|
||||
int eof();
|
||||
|
||||
int recv();
|
||||
int send(int ip, int port);
|
||||
int getIP();
|
||||
int getPort();
|
||||
int getMsgIP();
|
||||
int getMsgPort();
|
||||
|
||||
private:
|
||||
SOCKET sock;
|
||||
vector<char> in_buf, out_buf;
|
||||
sockaddr_in addr, in_addr, out_addr;
|
||||
int in_get, e;
|
||||
};
|
||||
|
||||
UDPStream::UDPStream(SOCKET s) :sock(s), in_get(0), e(0) {
|
||||
int len = sizeof(addr);
|
||||
getsockname(s, (sockaddr*)&addr, &len);
|
||||
in_addr = out_addr = addr;
|
||||
}
|
||||
|
||||
UDPStream::~UDPStream() {
|
||||
close(sock, e);
|
||||
}
|
||||
|
||||
int UDPStream::read(char *buff, int size) {
|
||||
if (e) return 0;
|
||||
int n = in_buf.size() - in_get;
|
||||
if (n < size) size = n;
|
||||
memcpy(buff, &in_buf[in_get], size);
|
||||
in_get += size;
|
||||
return size;
|
||||
}
|
||||
|
||||
int UDPStream::write(const char *buff, int size) {
|
||||
if (e) return 0;
|
||||
out_buf.insert(out_buf.end(), buff, buff + size);
|
||||
return size;
|
||||
}
|
||||
|
||||
int UDPStream::avail() {
|
||||
if (e) return 0;
|
||||
return in_buf.size() - in_get;
|
||||
}
|
||||
|
||||
int UDPStream::eof() {
|
||||
return e ? e : in_get == in_buf.size();
|
||||
}
|
||||
|
||||
//fill buffer, return sender
|
||||
int UDPStream::recv() {
|
||||
if (e) return 0;
|
||||
int tout;
|
||||
if (recv_timeout) tout = gx_runtime->getMilliSecs() + recv_timeout;
|
||||
for (;;) {
|
||||
int dt = 0;
|
||||
if (recv_timeout) {
|
||||
dt = tout - gx_runtime->getMilliSecs();
|
||||
if (dt < 0) dt = 0;
|
||||
}
|
||||
fd_set fd = { 1,sock };
|
||||
timeval tv = { dt / 1000,(dt % 1000) * 1000 };
|
||||
int n = ::select(0, &fd, 0, 0, &tv);
|
||||
if (!n) return 0;
|
||||
if (n != 1) { e = -1; return 0; }
|
||||
unsigned long sz = -1;
|
||||
if (ioctlsocket(sock, FIONREAD, &sz)) { e = -1; return 0; }
|
||||
in_buf.resize(sz); in_get = 0;
|
||||
int len = sizeof(in_addr);
|
||||
n = ::recvfrom(sock, &(in_buf.begin())[0], sz, 0, (sockaddr*)&in_addr, &len);
|
||||
if (n == SOCKET_ERROR) continue; //{ e=-1;return 0; }
|
||||
in_buf.resize(n);
|
||||
return getMsgIP();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//send, empty buffer
|
||||
int UDPStream::send(int ip, int port) {
|
||||
if (e) return 0;
|
||||
int sz = out_buf.size();
|
||||
out_addr.sin_addr.S_un.S_addr = htonl(ip);
|
||||
out_addr.sin_port = htons(port ? port : addr.sin_port);
|
||||
int n = ::sendto(sock, &(out_buf.begin())[0], sz, 0, (sockaddr*)&out_addr, sizeof(out_addr));
|
||||
if (n != sz) return e = -1;
|
||||
out_buf.clear();
|
||||
return sz;
|
||||
}
|
||||
|
||||
int UDPStream::getIP() {
|
||||
return ntohl(addr.sin_addr.S_un.S_addr);
|
||||
}
|
||||
|
||||
int UDPStream::getPort() {
|
||||
return ntohs(addr.sin_port);
|
||||
}
|
||||
|
||||
int UDPStream::getMsgIP() {
|
||||
return ntohl(in_addr.sin_addr.S_un.S_addr);
|
||||
}
|
||||
|
||||
int UDPStream::getMsgPort() {
|
||||
return ntohs(in_addr.sin_port);
|
||||
}
|
||||
|
||||
class TCPStream : public bbStream {
|
||||
public:
|
||||
TCPStream(SOCKET s, TCPServer *t);
|
||||
~TCPStream();
|
||||
|
||||
int read(char *buff, int size);
|
||||
int write(const char *buff, int size);
|
||||
int avail();
|
||||
int eof();
|
||||
|
||||
int getIP();
|
||||
int getPort();
|
||||
|
||||
private:
|
||||
SOCKET sock;
|
||||
TCPServer *server;
|
||||
int e, ip, port;
|
||||
};
|
||||
|
||||
class TCPServer {
|
||||
public:
|
||||
TCPServer(SOCKET S);
|
||||
~TCPServer();
|
||||
|
||||
TCPStream *accept();
|
||||
|
||||
void remove(TCPStream *s);
|
||||
|
||||
private:
|
||||
int e;
|
||||
SOCKET sock;
|
||||
set<TCPStream*> accepted_set;
|
||||
};
|
||||
|
||||
TCPStream::TCPStream(SOCKET s, TCPServer *t) :sock(s), server(t), e(0) {
|
||||
sockaddr_in addr;
|
||||
int len = sizeof(addr);
|
||||
if (getpeername(s, (sockaddr*)&addr, &len)) {
|
||||
ip = port = 0;
|
||||
return;
|
||||
}
|
||||
ip = ntohl(addr.sin_addr.S_un.S_addr);
|
||||
port = ntohs(addr.sin_port);
|
||||
}
|
||||
|
||||
TCPStream::~TCPStream() {
|
||||
if (server) server->remove(this);
|
||||
close(sock, e);
|
||||
}
|
||||
|
||||
int TCPStream::read(char *buff, int size) {
|
||||
if (e) return 0;
|
||||
char *b = buff, *l = buff + size;
|
||||
int tout;
|
||||
if (read_timeout) tout = gx_runtime->getMilliSecs() + read_timeout;
|
||||
while (b < l) {
|
||||
int dt = 0;
|
||||
if (read_timeout) {
|
||||
dt = tout - gx_runtime->getMilliSecs();
|
||||
if (dt < 0) dt = 0;
|
||||
}
|
||||
fd_set fd = { 1,sock };
|
||||
timeval tv = { dt / 1000,(dt % 1000) * 1000 };
|
||||
int n = ::select(0, &fd, 0, 0, &tv);
|
||||
if (n != 1) { e = -1; break; }
|
||||
n = ::recv(sock, b, l - b, 0);
|
||||
if (n == 0) { e = 1; break; }
|
||||
if (n == SOCKET_ERROR) { e = -1; break; }
|
||||
b += n;
|
||||
}
|
||||
return b - buff;
|
||||
}
|
||||
|
||||
int TCPStream::write(const char *buff, int size) {
|
||||
if (e) return 0;
|
||||
int n = ::send(sock, buff, size, 0);
|
||||
if (n == SOCKET_ERROR) { e = -1; return 0; }
|
||||
return n;
|
||||
}
|
||||
|
||||
int TCPStream::avail() {
|
||||
unsigned long t;
|
||||
int n = ::ioctlsocket(sock, FIONREAD, &t);
|
||||
if (n == SOCKET_ERROR) { e = -1; return 0; }
|
||||
return t;
|
||||
}
|
||||
|
||||
int TCPStream::eof() {
|
||||
if (e) return e;
|
||||
fd_set fd = { 1,sock };
|
||||
timeval tv = { 0,0 };
|
||||
switch (::select(0, &fd, 0, 0, &tv)) {
|
||||
case 0:break;
|
||||
case 1:if (!avail()) e = 1; break;
|
||||
default:e = -1;
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
int TCPStream::getIP() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
int TCPStream::getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
TCPServer::TCPServer(SOCKET s) :sock(s), e(0) {
|
||||
}
|
||||
|
||||
TCPServer::~TCPServer() {
|
||||
while (accepted_set.size()) delete *accepted_set.begin();
|
||||
close(sock, e);
|
||||
}
|
||||
|
||||
TCPStream *TCPServer::accept() {
|
||||
if (e) return 0;
|
||||
fd_set fd = { 1,sock };
|
||||
timeval tv = { accept_timeout / 1000,(accept_timeout % 1000) * 1000 };
|
||||
int n = ::select(0, &fd, 0, 0, &tv);
|
||||
if (n == 0) return 0;
|
||||
if (n != 1) { e = -1; return 0; }
|
||||
SOCKET t = ::accept(sock, 0, 0);
|
||||
if (t == INVALID_SOCKET) { e = -1; return 0; }
|
||||
TCPStream *s = d_new TCPStream(t, this);
|
||||
accepted_set.insert(s);
|
||||
return s;
|
||||
}
|
||||
|
||||
void TCPServer::remove(TCPStream *s) {
|
||||
accepted_set.erase(s);
|
||||
}
|
||||
|
||||
static inline void debugUDPStream(UDPStream *p) {
|
||||
if (debug && !udp_set.count(p)) {
|
||||
ThrowRuntimeException("UDP Stream does not exist");
|
||||
}
|
||||
}
|
||||
|
||||
static inline void debugTCPStream(TCPStream *p) {
|
||||
if (debug && !tcp_set.count(p)) {
|
||||
ThrowRuntimeException("TCP Stream does not exist");
|
||||
}
|
||||
}
|
||||
|
||||
static inline void debugTCPServer(TCPServer *p) {
|
||||
if (debug && !server_set.count(p)) {
|
||||
ThrowRuntimeException("TCP Server does not exist");
|
||||
}
|
||||
}
|
||||
|
||||
static vector<int> host_ips;
|
||||
|
||||
int bbCountHostIPs(BBStr *host) {
|
||||
host_ips.clear();
|
||||
HOSTENT *h = gethostbyname(host->c_str());
|
||||
delete host; if (!h) return 0;
|
||||
char **p = h->h_addr_list;
|
||||
while (char *t = *p++) host_ips.push_back(ntohl(*(int*)t));
|
||||
return host_ips.size();
|
||||
}
|
||||
|
||||
int bbHostIP(int index) {
|
||||
if (debug) {
|
||||
if (index<1 || index>host_ips.size()) {
|
||||
ThrowRuntimeException("Host index out of range");
|
||||
}
|
||||
}
|
||||
return host_ips[index - 1];
|
||||
}
|
||||
|
||||
UDPStream *bbCreateUDPStream(int port) {
|
||||
if (!socks_ok) return 0;
|
||||
SOCKET s = ::socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (s != INVALID_SOCKET) {
|
||||
sockaddr_in addr = { AF_INET,htons(port) };
|
||||
if (!::bind(s, (sockaddr*)&addr, sizeof(addr))) {
|
||||
UDPStream *p = d_new UDPStream(s);
|
||||
udp_set.insert(p);
|
||||
return p;
|
||||
}
|
||||
::closesocket(s);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void bbCloseUDPStream(UDPStream *p) {
|
||||
debugUDPStream(p);
|
||||
udp_set.erase(p);
|
||||
delete p;
|
||||
}
|
||||
|
||||
int bbRecvUDPMsg(UDPStream *p) {
|
||||
debugUDPStream(p);
|
||||
return p->recv();
|
||||
}
|
||||
|
||||
void bbSendUDPMsg(UDPStream *p, int ip, int port) {
|
||||
debugUDPStream(p);
|
||||
p->send(ip, port);
|
||||
}
|
||||
|
||||
int bbUDPStreamIP(UDPStream *p) {
|
||||
debugUDPStream(p);
|
||||
return p->getIP();
|
||||
}
|
||||
|
||||
int bbUDPStreamPort(UDPStream *p) {
|
||||
debugUDPStream(p);
|
||||
return p->getPort();
|
||||
}
|
||||
|
||||
int bbUDPMsgIP(UDPStream *p) {
|
||||
debugUDPStream(p);
|
||||
return p->getMsgIP();
|
||||
}
|
||||
|
||||
int bbUDPMsgPort(UDPStream *p) {
|
||||
debugUDPStream(p);
|
||||
return p->getMsgPort();
|
||||
}
|
||||
|
||||
void bbUDPTimeouts(int rt) {
|
||||
recv_timeout = rt;
|
||||
}
|
||||
|
||||
BBStr *bbDottedIP(int ip) {
|
||||
return d_new BBStr(
|
||||
itoa((ip >> 24) & 255) + "." + itoa((ip >> 16) & 255) + "." +
|
||||
itoa((ip >> 8) & 255) + "." + itoa(ip & 255));
|
||||
}
|
||||
|
||||
static int findHostIP(const string &t) {
|
||||
int ip = inet_addr(t.c_str());
|
||||
if (ip != INADDR_NONE) return ip;
|
||||
HOSTENT *h = gethostbyname(t.c_str());
|
||||
if (!h) return -1;
|
||||
char *p;
|
||||
for (char **list = h->h_addr_list; p = *list; ++list) {
|
||||
return *(int*)p;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
TCPStream *bbOpenTCPStream(BBStr *server, int port, int local_port) {
|
||||
if (!socks_ok) {
|
||||
delete server;
|
||||
return 0;
|
||||
}
|
||||
int ip = findHostIP(*server); delete server;
|
||||
if (ip == -1) return 0;
|
||||
SOCKET s = ::socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (s != INVALID_SOCKET) {
|
||||
if (local_port) {
|
||||
sockaddr_in addr = { AF_INET,htons(local_port) };
|
||||
if (::bind(s, (sockaddr*)&addr, sizeof(addr))) {
|
||||
::closesocket(s);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
sockaddr_in addr = { AF_INET,htons(port) };
|
||||
addr.sin_addr.S_un.S_addr = ip;
|
||||
if (!::connect(s, (sockaddr*)&addr, sizeof(addr))) {
|
||||
TCPStream *p = d_new TCPStream(s, 0);
|
||||
tcp_set.insert(p);
|
||||
return p;
|
||||
}
|
||||
::closesocket(s);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void bbCloseTCPStream(TCPStream *p) {
|
||||
debugTCPStream(p);
|
||||
tcp_set.erase(p);
|
||||
delete p;
|
||||
}
|
||||
|
||||
TCPServer * bbCreateTCPServer(int port) {
|
||||
SOCKET s = ::socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (s != INVALID_SOCKET) {
|
||||
sockaddr_in addr = { AF_INET,htons(port) };
|
||||
if (!::bind(s, (sockaddr*)&addr, sizeof(addr))) {
|
||||
if (!::listen(s, SOMAXCONN)) {
|
||||
TCPServer *p = d_new TCPServer(s);
|
||||
server_set.insert(p);
|
||||
return p;
|
||||
}
|
||||
}
|
||||
::closesocket(s);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void bbCloseTCPServer(TCPServer *p) {
|
||||
debugTCPServer(p);
|
||||
server_set.erase(p);
|
||||
delete p;
|
||||
}
|
||||
|
||||
TCPStream * bbAcceptTCPStream(TCPServer *server) {
|
||||
debugTCPServer(server);
|
||||
if (!gx_runtime->idle()) ThrowRuntimeException(0);
|
||||
if (TCPStream *tcp = server->accept()) {
|
||||
tcp_set.insert(tcp);
|
||||
return tcp;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bbTCPStreamIP(TCPStream *p) {
|
||||
debugTCPStream(p);
|
||||
return p->getIP();
|
||||
}
|
||||
|
||||
int bbTCPStreamPort(TCPStream *p) {
|
||||
debugTCPStream(p);
|
||||
return p->getPort();
|
||||
}
|
||||
|
||||
void bbTCPTimeouts(int rt, int at) {
|
||||
read_timeout = rt;
|
||||
accept_timeout = at;
|
||||
}
|
||||
|
||||
bool sockets_create() {
|
||||
socks_ok = WSAStartup(0x0101, &wsadata) == 0;
|
||||
recv_timeout = 0;
|
||||
read_timeout = 10000;
|
||||
accept_timeout = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool sockets_destroy() {
|
||||
while (udp_set.size()) bbCloseUDPStream(*udp_set.begin());
|
||||
while (tcp_set.size()) bbCloseTCPStream(*tcp_set.begin());
|
||||
while (server_set.size()) bbCloseTCPServer(*server_set.begin());
|
||||
if (socks_ok) WSACleanup();
|
||||
return true;
|
||||
}
|
||||
|
||||
void sockets_link(void(*rtSym)(const char*, void*)) {
|
||||
rtSym("$DottedIP%IP", bbDottedIP);
|
||||
rtSym("%CountHostIPs$host_name", bbCountHostIPs);
|
||||
rtSym("%HostIP%host_index", bbHostIP);
|
||||
|
||||
rtSym("%CreateUDPStream%port=0", bbCreateUDPStream);
|
||||
rtSym("CloseUDPStream%udp_stream", bbCloseUDPStream);
|
||||
rtSym("SendUDPMsg%udp_stream%dest_ip%dest_port=0", bbSendUDPMsg);
|
||||
rtSym("%RecvUDPMsg%udp_stream", bbRecvUDPMsg);
|
||||
rtSym("%UDPStreamIP%udp_stream", bbUDPStreamIP);
|
||||
rtSym("%UDPStreamPort%udp_stream", bbUDPStreamPort);
|
||||
rtSym("%UDPMsgIP%udp_stream", bbUDPMsgIP);
|
||||
rtSym("%UDPMsgPort%udp_stream", bbUDPMsgPort);
|
||||
rtSym("UDPTimeouts%recv_timeout", bbUDPTimeouts);
|
||||
|
||||
rtSym("%OpenTCPStream$server%server_port%local_port=0", bbOpenTCPStream);
|
||||
rtSym("CloseTCPStream%tcp_stream", bbCloseTCPStream);
|
||||
rtSym("%CreateTCPServer%port", bbCreateTCPServer);
|
||||
rtSym("CloseTCPServer%tcp_server", bbCloseTCPServer);
|
||||
rtSym("%AcceptTCPStream%tcp_server", bbAcceptTCPStream);
|
||||
rtSym("%TCPStreamIP%tcp_stream", bbTCPStreamIP);
|
||||
rtSym("%TCPStreamPort%tcp_stream", bbTCPStreamPort);
|
||||
rtSym("TCPTimeouts%read_millis%accept_millis", bbTCPTimeouts);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
#ifndef BBSOCKETS_H
|
||||
#define BBSOCKETS_H
|
||||
|
||||
#include "bbstream.h"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "bbstream.h"
|
||||
|
||||
static set<bbStream*> stream_set;
|
||||
|
||||
void debugStream( bbStream *s ){
|
||||
if( stream_set.count(s) ) return;
|
||||
ThrowRuntimeException( "Stream does not exist" );
|
||||
}
|
||||
|
||||
bbStream::bbStream(){
|
||||
stream_set.insert( this );
|
||||
}
|
||||
|
||||
bbStream::~bbStream(){
|
||||
stream_set.erase( this );
|
||||
}
|
||||
|
||||
int bbEof( bbStream *s ){
|
||||
if( debug ) debugStream( s );
|
||||
return s->eof();
|
||||
}
|
||||
|
||||
int bbReadAvail( bbStream *s ){
|
||||
if( debug ) debugStream( s );
|
||||
return s->avail();
|
||||
}
|
||||
|
||||
int bbReadByte( bbStream *s ){
|
||||
if( debug ) debugStream( s );
|
||||
int n=0;
|
||||
s->read( (char*)&n,1 );
|
||||
return n;
|
||||
}
|
||||
|
||||
int bbReadShort( bbStream *s ){
|
||||
if( debug ) debugStream( s );
|
||||
int n=0;
|
||||
s->read( (char*)&n,2 );
|
||||
return n;
|
||||
}
|
||||
|
||||
int bbReadInt( bbStream *s ){
|
||||
if( debug ) debugStream( s );
|
||||
int n=0;
|
||||
s->read( (char*)&n,4 );
|
||||
return n;
|
||||
}
|
||||
|
||||
float bbReadFloat( bbStream *s ){
|
||||
if( debug ) debugStream( s );
|
||||
float n=0;
|
||||
s->read( (char*)&n,4 );
|
||||
return n;
|
||||
}
|
||||
|
||||
BBStr *bbReadString( bbStream *s ){
|
||||
if( debug ) debugStream( s );
|
||||
int len;
|
||||
BBStr *str=d_new BBStr();
|
||||
if( s->read( (char*)&len,4 ) ){
|
||||
char *buff=d_new char[len];
|
||||
if( s->read( buff,len ) ){
|
||||
*str=string( buff,len );
|
||||
}
|
||||
delete[] buff;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
BBStr *bbReadLine( bbStream *s ){
|
||||
if( debug ) debugStream( s );
|
||||
unsigned char c;
|
||||
BBStr *str=d_new BBStr();
|
||||
for(;;){
|
||||
if( s->read( (char*)&c,1 )!=1 ) break;
|
||||
if( c=='\n' ) break;
|
||||
if( c!='\r' ) *str+=c;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
void bbWriteByte( bbStream *s,int n ){
|
||||
if( debug ) debugStream( s );
|
||||
s->write( (char*)&n,1 );
|
||||
}
|
||||
|
||||
void bbWriteShort( bbStream *s,int n ){
|
||||
if( debug ) debugStream( s );
|
||||
s->write( (char*)&n,2 );
|
||||
}
|
||||
|
||||
void bbWriteInt( bbStream *s,int n ){
|
||||
if( debug ) debugStream( s );
|
||||
s->write( (char*)&n,4 );
|
||||
}
|
||||
|
||||
void bbWriteFloat( bbStream *s,float n ){
|
||||
if( debug ) debugStream( s );
|
||||
s->write( (char*)&n,4 );
|
||||
}
|
||||
|
||||
void bbWriteString( bbStream *s,BBStr *t ){
|
||||
if( debug ) debugStream( s );
|
||||
int n=t->size();
|
||||
s->write( (char*)&n,4 );
|
||||
s->write( t->data(),t->size() );
|
||||
delete t;
|
||||
}
|
||||
|
||||
void bbWriteLine( bbStream *s,BBStr *t ){
|
||||
if( debug ) debugStream( s );
|
||||
s->write( t->data(),t->size() );
|
||||
s->write( "\r\n",2 );
|
||||
delete t;
|
||||
}
|
||||
|
||||
void bbCopyStream( bbStream *s,bbStream *d,int buff_size ){
|
||||
if( debug ){
|
||||
debugStream( s );debugStream( d );
|
||||
if( buff_size<1 || buff_size>1024*1024 ) ThrowRuntimeException( "Illegal buffer size" );
|
||||
}
|
||||
char *buff=d_new char[buff_size];
|
||||
while( s->eof()==0 && d->eof()==0 ){
|
||||
int n=s->read( buff,buff_size );
|
||||
d->write( buff,n );
|
||||
if( n<buff_size ) break;
|
||||
}
|
||||
delete buff;
|
||||
}
|
||||
|
||||
bool stream_create(){
|
||||
return true;
|
||||
}
|
||||
|
||||
bool stream_destroy(){
|
||||
return true;
|
||||
}
|
||||
|
||||
void stream_link( void(*rtSym)(const char*,void*) ){
|
||||
rtSym( "%Eof%stream",bbEof );
|
||||
rtSym( "%ReadAvail%stream",bbReadAvail );
|
||||
rtSym( "%ReadByte%stream",bbReadByte );
|
||||
rtSym( "%ReadShort%stream",bbReadShort );
|
||||
rtSym( "%ReadInt%stream",bbReadInt );
|
||||
rtSym( "#ReadFloat%stream",bbReadFloat );
|
||||
rtSym( "$ReadString%stream",bbReadString );
|
||||
rtSym( "$ReadLine%stream",bbReadLine );
|
||||
rtSym( "WriteByte%stream%byte",bbWriteByte );
|
||||
rtSym( "WriteShort%stream%short",bbWriteShort );
|
||||
rtSym( "WriteInt%stream%int",bbWriteInt );
|
||||
rtSym( "WriteFloat%stream#float",bbWriteFloat );
|
||||
rtSym( "WriteString%stream$string",bbWriteString );
|
||||
rtSym( "WriteLine%stream$string",bbWriteLine );
|
||||
rtSym( "CopyStream%src_stream%dest_stream%buffer_size=16384",bbCopyStream );
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
|
||||
#ifndef BBSTREAM_H
|
||||
#define BBSTREAM_H
|
||||
|
||||
#include "bbsys.h"
|
||||
|
||||
class bbStream{
|
||||
public:
|
||||
enum{
|
||||
EOF_ERROR=-1,EOF_NOT=0,EOF_OK=1
|
||||
};
|
||||
|
||||
bbStream();
|
||||
virtual ~bbStream();
|
||||
|
||||
//returns chars read
|
||||
virtual int read( char *buff,int size )=0;
|
||||
|
||||
//returns chars written
|
||||
virtual int write( const char *buff,int size )=0;
|
||||
|
||||
//returns chars avilable for reading
|
||||
virtual int avail()=0;
|
||||
|
||||
//returns EOF status
|
||||
virtual int eof()=0;
|
||||
};
|
||||
|
||||
void debugStream( bbStream *s );
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,162 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "bbsys.h"
|
||||
#include <time.h>
|
||||
|
||||
#define CHKPOS(x) if( (x)<0 ) ThrowRuntimeException( "parameter must be positive" );
|
||||
#define CHKOFF(x) if( (x)<=0 ) ThrowRuntimeException( "parameter must be greater than 0" );
|
||||
|
||||
BBStr *bbString( BBStr *s,int n ){
|
||||
BBStr *t=d_new BBStr();
|
||||
while( n-->0 ) *t+=*s;
|
||||
delete s;return t;
|
||||
}
|
||||
|
||||
BBStr *bbLeft( BBStr *s,int n ){
|
||||
CHKPOS( n );
|
||||
*s=s->substr( 0,n );return s;
|
||||
}
|
||||
|
||||
BBStr *bbRight( BBStr *s,int n ){
|
||||
CHKPOS( n );
|
||||
n=s->size()-n;if( n<0 ) n=0;
|
||||
*s=s->substr( n );return s;
|
||||
}
|
||||
|
||||
BBStr *bbReplace( BBStr *s,BBStr *from,BBStr *to ){
|
||||
int n=0,from_sz=from->size(),to_sz=to->size();
|
||||
while( n<s->size() && (n=s->find( *from,n ))!=string::npos ){
|
||||
s->replace( n,from_sz,*to );
|
||||
n+=to_sz;
|
||||
}
|
||||
delete from;delete to;return s;
|
||||
}
|
||||
|
||||
int bbInstr( BBStr *s,BBStr *t,int from ){
|
||||
CHKOFF( from );--from;
|
||||
int n=s->find( *t,from );
|
||||
delete s;delete t;
|
||||
return n==string::npos ? 0 : n+1;
|
||||
}
|
||||
|
||||
BBStr *bbMid( BBStr *s,int o,int n ){
|
||||
CHKOFF( o );--o;
|
||||
if( o>s->size() ) o=s->size();
|
||||
if( n>=0 ) *s=s->substr( o,n );
|
||||
else *s=s->substr( o );
|
||||
return s;
|
||||
}
|
||||
|
||||
BBStr *bbUpper( BBStr *s ){
|
||||
for( int k=0;k<s->size();++k ) (*s)[k]=toupper( (*s)[k] );
|
||||
return s;
|
||||
}
|
||||
|
||||
BBStr *bbLower( BBStr *s ){
|
||||
for( int k=0;k<s->size();++k ) (*s)[k]=tolower( (*s)[k] );
|
||||
return s;
|
||||
}
|
||||
|
||||
BBStr *bbTrim( BBStr *s ){
|
||||
int n=0,p=s->size();
|
||||
while( n<s->size() && !isgraph( (*s)[n] ) ) ++n;
|
||||
while( p>n && !isgraph( (*s)[p-1] ) ) --p;
|
||||
*s=s->substr( n,p-n );return s;
|
||||
}
|
||||
|
||||
BBStr *bbLSet( BBStr *s,int n ){
|
||||
CHKPOS(n);
|
||||
if( s->size()>n ) *s=s->substr( 0,n );
|
||||
else{
|
||||
while( s->size()<n ) *s+=' ';
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
BBStr *bbRSet( BBStr *s,int n ){
|
||||
CHKPOS(n);
|
||||
if( s->size()>n ) *s=s->substr( s->size()-n );
|
||||
else{
|
||||
while( s->size()<n ) *s=' '+*s;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
BBStr *bbChr( int n ){
|
||||
BBStr *t=d_new BBStr();
|
||||
*t+=(char)n;return t;
|
||||
}
|
||||
|
||||
BBStr *bbHex( int n ){
|
||||
char buff[12];
|
||||
for( int k=7;k>=0;n>>=4,--k ){
|
||||
int t=(n&15)+'0';
|
||||
buff[k]=t>'9' ? t+='A'-'9'-1 : t;
|
||||
}
|
||||
buff[8]=0;
|
||||
return d_new BBStr( buff );
|
||||
}
|
||||
|
||||
BBStr *bbBin( int n ){
|
||||
char buff[36];
|
||||
for( int k=31;k>=0;n>>=1,--k ){
|
||||
buff[k]=n&1 ? '1' : '0';
|
||||
}
|
||||
buff[32]=0;
|
||||
return d_new BBStr( buff );
|
||||
}
|
||||
|
||||
int bbAsc( BBStr *s ){
|
||||
int n=s->size() ? (*s)[0] & 255 : -1;
|
||||
delete s;return n;
|
||||
}
|
||||
|
||||
int bbLen( BBStr *s ){
|
||||
int n=s->size();
|
||||
delete s;return n;
|
||||
}
|
||||
|
||||
BBStr *bbCurrentDate(){
|
||||
time_t t;
|
||||
time( &t );
|
||||
char buff[256];
|
||||
strftime( buff,256,"%d %b %Y",localtime( &t ) );
|
||||
return d_new BBStr( buff );
|
||||
}
|
||||
|
||||
BBStr *bbCurrentTime(){
|
||||
time_t t;
|
||||
time( &t );
|
||||
char buff[256];
|
||||
strftime( buff,256,"%H:%M:%S",localtime( &t ) );
|
||||
return d_new BBStr( buff );
|
||||
}
|
||||
|
||||
bool string_create(){
|
||||
return true;
|
||||
}
|
||||
|
||||
bool string_destroy(){
|
||||
return true;
|
||||
}
|
||||
|
||||
void string_link( void(*rtSym)(const char*,void*) ){
|
||||
rtSym( "$String$string%repeat",bbString );
|
||||
rtSym( "$Left$string%count",bbLeft );
|
||||
rtSym( "$Right$string%count",bbRight );
|
||||
rtSym( "$Replace$string$from$to",bbReplace );
|
||||
rtSym( "%Instr$string$find%from=1",bbInstr );
|
||||
rtSym( "$Mid$string%start%count=-1",bbMid );
|
||||
rtSym( "$Upper$string",bbUpper );
|
||||
rtSym( "$Lower$string",bbLower );
|
||||
rtSym( "$Trim$string",bbTrim );
|
||||
rtSym( "$LSet$string%size",bbLSet );
|
||||
rtSym( "$RSet$string%size",bbRSet );
|
||||
rtSym( "$Chr%ascii",bbChr );
|
||||
rtSym( "%Asc$string",bbAsc );
|
||||
rtSym( "%Len$string",bbLen );
|
||||
rtSym( "$Hex%value",bbHex );
|
||||
rtSym( "$Bin%value",bbBin );
|
||||
rtSym( "$CurrentDate",bbCurrentDate );
|
||||
rtSym( "$CurrentTime",bbCurrentTime );
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
#ifndef BBSTRING_H
|
||||
#define BBSTRING_H
|
||||
|
||||
#include "basic.h"
|
||||
|
||||
BBStr * bbString( BBStr *s,int n );
|
||||
BBStr * bbLeft( BBStr *s,int n );
|
||||
BBStr * bbRight( BBStr *s,int n );
|
||||
BBStr * bbReplace( BBStr *s,BBStr *from,BBStr *to );
|
||||
int bbInstr( BBStr *s,BBStr *t,int from );
|
||||
BBStr * bbMid( BBStr *s,int o,int n );
|
||||
BBStr * bbUpper( BBStr *s );
|
||||
BBStr * bbLower( BBStr *s );
|
||||
BBStr * bbTrim( BBStr *s );
|
||||
BBStr * bbLSet( BBStr *s,int n );
|
||||
BBStr * bbRSet( BBStr *s,int n );
|
||||
BBStr * bbChr( int n );
|
||||
int bbAsc( BBStr *s );
|
||||
int bbLen( BBStr *s );
|
||||
BBStr * bbHex( int n );
|
||||
BBStr * bbBin( int n );
|
||||
BBStr * bbCurrentDate();
|
||||
BBStr * bbCurrentTime();
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "bbsys.h"
|
||||
|
||||
bool debug;
|
||||
gxRuntime *gx_runtime;
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
#ifndef BBSYS_H
|
||||
#define BBSYS_H
|
||||
|
||||
#include "basic.h"
|
||||
#include "../gxruntime/gxruntime.h"
|
||||
|
||||
extern bool debug;
|
||||
extern gxRuntime *gx_runtime;
|
||||
|
||||
struct bbEx{
|
||||
const char *err;
|
||||
bbEx( const char *e ):err(e){
|
||||
if( e ) gx_runtime->debugError( e );
|
||||
}
|
||||
};
|
||||
|
||||
#define ThrowRuntimeException( _X_ ) throw bbEx( _X_ );
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,309 @@
|
||||
|
||||
/*
|
||||
|
||||
Note - does not appear to like DPSESSION_MULTICASTSERVER very much!
|
||||
|
||||
*/
|
||||
|
||||
#include "std.h"
|
||||
#include "multiplay.h"
|
||||
#include "multiplay_setup.h"
|
||||
|
||||
//struct Player;
|
||||
//
|
||||
//static bool host;
|
||||
//
|
||||
//static map<DPID,Player*> player_map;
|
||||
//static list<Player*> players,new_players;
|
||||
//
|
||||
//static int msg_type;
|
||||
//static string msg_data;
|
||||
//static DPID msg_from,msg_to;
|
||||
//
|
||||
//static char *recv_buff;
|
||||
//static int recv_buff_sz;
|
||||
//
|
||||
//static char *send_buff;
|
||||
//static int send_buff_sz;
|
||||
//
|
||||
//#pragma pack( push,1 )
|
||||
//struct bbMsg{
|
||||
// DPID from,to;
|
||||
// char type;
|
||||
//};
|
||||
//#pragma pack( pop )
|
||||
//
|
||||
//struct Player{
|
||||
// DPID id;
|
||||
// string name;
|
||||
// bool remote;
|
||||
//
|
||||
// Player( DPID i,const string &n,bool r ):id(i),name(n),remote(r){
|
||||
// players.push_back( this );
|
||||
// if( remote ) new_players.push_back( this );
|
||||
// player_map.clear();
|
||||
// }
|
||||
//
|
||||
// Player::~Player(){
|
||||
// new_players.remove( this );
|
||||
// players.remove( this );
|
||||
// player_map.clear();
|
||||
// }
|
||||
//};
|
||||
//
|
||||
//static void chk(){
|
||||
// if( !dirPlay ){
|
||||
// RTEX( "Multiplayer game not started" );
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//static void clearPlayers(){
|
||||
// while( players.size() ) delete players.back();
|
||||
// new_players.clear();
|
||||
// player_map.clear();
|
||||
//}
|
||||
//
|
||||
//static Player *findPlayer( DPID id ){
|
||||
// if( !player_map.size() ){
|
||||
// list<Player*>::iterator it;
|
||||
// for( it=players.begin();it!=players.end();++it ){
|
||||
// player_map.insert( pair<DPID,Player*>( (*it)->id,(*it) ) );
|
||||
// }
|
||||
// }
|
||||
// map<DPID,Player*>::iterator it=player_map.find( id );
|
||||
// return it==player_map.end() ? 0 : it->second;
|
||||
//}
|
||||
//
|
||||
//static BOOL FAR PASCAL enumPlayer( DPID id,DWORD type,LPCDPNAME name,DWORD flags,LPVOID context ){
|
||||
// Player *p=findPlayer( id );if( p ) return TRUE;
|
||||
// p=d_new Player( id,string( name->lpszShortNameA ),true );
|
||||
// return TRUE;
|
||||
//}
|
||||
//
|
||||
//void multiplay_link( void(*rtSym)(const char*,void*) ){
|
||||
// rtSym( "%StartNetGame",bbStartNetGame );
|
||||
// rtSym( "%HostNetGame$game_name",bbHostNetGame );
|
||||
// rtSym( "%JoinNetGame$game_name$ip_address",bbJoinNetGame );
|
||||
// rtSym( "StopNetGame",bbStopNetGame );
|
||||
//
|
||||
// rtSym( "%CreateNetPlayer$name",bbCreateNetPlayer );
|
||||
// rtSym( "DeleteNetPlayer%player",bbDeleteNetPlayer );
|
||||
// rtSym( "$NetPlayerName%player",bbNetPlayerName );
|
||||
// rtSym( "%NetPlayerLocal%player",bbNetPlayerLocal );
|
||||
//
|
||||
// rtSym( "%SendNetMsg%type$msg%from_player%to_player=0%reliable=1",bbSendNetMsg );
|
||||
//
|
||||
// rtSym( "%RecvNetMsg",bbRecvNetMsg );
|
||||
// rtSym( "%NetMsgType",bbNetMsgType );
|
||||
// rtSym( "%NetMsgFrom",bbNetMsgFrom );
|
||||
// rtSym( "%NetMsgTo",bbNetMsgTo );
|
||||
// rtSym( "$NetMsgData",bbNetMsgData );
|
||||
//}
|
||||
//
|
||||
//bool multiplay_create(){
|
||||
//
|
||||
// recv_buff_sz=send_buff_sz=1024;
|
||||
// recv_buff=d_new char[recv_buff_sz];
|
||||
// send_buff=d_new char[send_buff_sz];
|
||||
//
|
||||
// multiplay_setup_create();
|
||||
//
|
||||
// return true;
|
||||
//}
|
||||
//
|
||||
//bool multiplay_destroy(){
|
||||
//
|
||||
// bbStopNetGame();
|
||||
//
|
||||
// multiplay_setup_destroy();
|
||||
//
|
||||
// delete[] recv_buff;recv_buff=0;
|
||||
// delete[] send_buff;send_buff=0;
|
||||
//
|
||||
// return true;
|
||||
//}
|
||||
//
|
||||
//static int startGame( int n ){
|
||||
// clearPlayers();
|
||||
// if( !n ) return 0;
|
||||
// if( dirPlay->EnumPlayers( 0,enumPlayer,0,0 )>=0 ){
|
||||
// host=n==2;
|
||||
// return n;
|
||||
// }
|
||||
// multiplay_setup_close();
|
||||
// return 0;
|
||||
//}
|
||||
//
|
||||
//int bbStartNetGame(){
|
||||
// if( dirPlay ){
|
||||
// RTEX( "Multiplayer game already started" );
|
||||
// }
|
||||
// return startGame( multiplay_setup_open() );
|
||||
//}
|
||||
//
|
||||
//int bbHostNetGame( BBStr *name ){
|
||||
// if( dirPlay ){
|
||||
// RTEX( "Multiplayer game already started" );
|
||||
// }
|
||||
// string n=*name;delete name;
|
||||
// return startGame( multiplay_setup_host( n ) );
|
||||
//}
|
||||
//
|
||||
//int bbJoinNetGame( BBStr *name,BBStr *address ){
|
||||
// if( dirPlay ){
|
||||
// RTEX( "Multiplayer game already started" );
|
||||
// }
|
||||
// string n=*name,a=*address;delete name;delete address;
|
||||
// return startGame( multiplay_setup_join( n,a ) );
|
||||
//}
|
||||
//
|
||||
//void bbStopNetGame(){
|
||||
// multiplay_setup_close();
|
||||
// clearPlayers();
|
||||
//}
|
||||
//
|
||||
//DPID bbCreateNetPlayer( BBStr *nm ){
|
||||
// chk();
|
||||
//
|
||||
// string t=*nm;
|
||||
// string t0=t+'\0';
|
||||
// delete nm;
|
||||
//
|
||||
// DPID id;
|
||||
// DPNAME name;
|
||||
// memset( &name,0,sizeof( name ) );
|
||||
// name.dwSize=sizeof(name);name.lpszShortNameA=(char*)t0.data();
|
||||
//
|
||||
// if( dirPlay->CreatePlayer( &id,&name,0,0,0,0 )<0 ) return 0;
|
||||
//
|
||||
// Player *p=d_new Player( id,t,false );
|
||||
//
|
||||
// if( players.size()==1 ){
|
||||
// if( dirPlay->EnumPlayers( 0,enumPlayer,0,0 )<0 ){
|
||||
// dirPlay->DestroyPlayer( id );
|
||||
// delete p;
|
||||
// return 0;
|
||||
// }
|
||||
// }
|
||||
// return id;
|
||||
//}
|
||||
//
|
||||
//void bbDeleteNetPlayer( DPID player ){
|
||||
// chk();
|
||||
//
|
||||
// if( Player *p=findPlayer( player ) ){
|
||||
// dirPlay->DestroyPlayer( player );
|
||||
// delete p;
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//BBStr *bbNetPlayerName( DPID player ){
|
||||
// if( !player ) return d_new BBStr( "<all>" );
|
||||
// Player *p=findPlayer( player );
|
||||
// return d_new BBStr( p ? p->name : "<unknown>" );
|
||||
//}
|
||||
//
|
||||
//int bbNetPlayerLocal( DPID player ){
|
||||
// if( Player *p=findPlayer( player ) ) return p->remote ? 0 : 1;
|
||||
// return 0;
|
||||
//}
|
||||
//
|
||||
//int bbRecvNetMsg(){
|
||||
// chk();
|
||||
//
|
||||
// msg_type=0;
|
||||
// msg_data.resize(0);
|
||||
// msg_from=DPID_UNKNOWN;msg_to=DPID_ALLPLAYERS;
|
||||
//
|
||||
// while( !msg_type ){
|
||||
//
|
||||
// if( new_players.size() ){
|
||||
// msg_from=new_players.front()->id;
|
||||
// new_players.pop_front();
|
||||
// msg_type=100;
|
||||
// return 1;
|
||||
// }
|
||||
//
|
||||
// DPID from,to;
|
||||
// DWORD sz=recv_buff_sz;
|
||||
// int n=dirPlay->Receive( &from,&to,0,recv_buff,&sz );
|
||||
//
|
||||
// if( n==DPERR_BUFFERTOOSMALL ){
|
||||
// sz=recv_buff_sz=sz/2+sz;
|
||||
// delete[] recv_buff;recv_buff=d_new char[recv_buff_sz];
|
||||
// n=dirPlay->Receive( &from,&to,0,recv_buff,&sz );
|
||||
// }
|
||||
//
|
||||
// if( n!=DP_OK ) return 0;
|
||||
//
|
||||
// if( from==DPID_SYSMSG ){
|
||||
// switch( *(DWORD*)recv_buff ){
|
||||
// case DPSYS_CREATEPLAYERORGROUP:
|
||||
// if( DPMSG_CREATEPLAYERORGROUP *msg=(DPMSG_CREATEPLAYERORGROUP*)recv_buff ){
|
||||
// if( findPlayer( from=msg->dpId ) ) continue;
|
||||
// d_new Player( from,string( msg->dpnName.lpszShortNameA ),true );
|
||||
// continue;
|
||||
// }
|
||||
// break;
|
||||
// case DPSYS_DESTROYPLAYERORGROUP:
|
||||
// if( DPMSG_DESTROYPLAYERORGROUP *msg=(DPMSG_DESTROYPLAYERORGROUP*)recv_buff ){
|
||||
// Player *p=findPlayer( msg->dpId );if( !p ) continue;
|
||||
// delete p;msg_from=msg->dpId;msg_type=101;
|
||||
// }
|
||||
// break;
|
||||
// case DPSYS_HOST:
|
||||
// if( !host ){
|
||||
// host=true;msg_type=102;
|
||||
// }
|
||||
// break;
|
||||
// case DPSYS_SESSIONLOST:
|
||||
// msg_type=200;
|
||||
// break;
|
||||
// }
|
||||
// }else{
|
||||
// bbMsg *m=(bbMsg*)recv_buff;
|
||||
// Player *p=findPlayer( m->from );
|
||||
// if( p && !p->remote ) continue;
|
||||
// msg_data=string( (char*)(m+1),sz-sizeof(bbMsg) );
|
||||
// msg_from=m->from;msg_to=m->to;
|
||||
// msg_type=m->type;
|
||||
// }
|
||||
// }
|
||||
// return 1;
|
||||
//}
|
||||
//
|
||||
//int bbNetMsgType(){
|
||||
// return msg_type;
|
||||
//}
|
||||
//
|
||||
//BBStr *bbNetMsgData(){
|
||||
// return d_new BBStr( msg_data );
|
||||
//}
|
||||
//
|
||||
//DPID bbNetMsgFrom(){
|
||||
// return msg_from;
|
||||
//}
|
||||
//
|
||||
//DPID bbNetMsgTo(){
|
||||
// return msg_to;
|
||||
//}
|
||||
//
|
||||
//int bbSendNetMsg( int type,BBStr *msg,DPID from,DPID to,int reliable ){
|
||||
// chk();
|
||||
//
|
||||
// int sz=msg->size()+sizeof(bbMsg);
|
||||
// if( sz>send_buff_sz ){
|
||||
// send_buff_sz=sz/2+sz;
|
||||
// delete send_buff;send_buff=d_new char[send_buff_sz];
|
||||
// }
|
||||
// bbMsg *m=(bbMsg*)send_buff;
|
||||
// m->type=type;m->from=from;m->to=to;
|
||||
//
|
||||
// memcpy( m+1,msg->data(),msg->size() );
|
||||
//
|
||||
// if( !to ) to=DPID_ALLPLAYERS;
|
||||
// int n=dirPlay->Send( from,to,reliable ? DPSEND_GUARANTEED : 0,send_buff,sz );
|
||||
// delete msg;
|
||||
//
|
||||
// return n>=0;
|
||||
//}
|
||||
@@ -0,0 +1,30 @@
|
||||
|
||||
#ifndef MULTIPLAY_H
|
||||
#define MULTIPLAY_H
|
||||
|
||||
#include "bbsys.h"
|
||||
//#include <dplay.h>
|
||||
|
||||
//void multiplay_link();
|
||||
//bool multiplay_create();
|
||||
//bool multiplay_destroy();
|
||||
//
|
||||
//int bbStartNetGame();
|
||||
//int bbHostNetGame( BBStr *name );
|
||||
//int bbJoinNetGame( BBStr *name,BBStr *address );
|
||||
//void bbStopNetGame();
|
||||
//
|
||||
//DPID bbCreateNetPlayer( BBStr *name );
|
||||
//void bbDeleteNetPlayer( DPID player );
|
||||
//BBStr * bbNetPlayerName( DPID player );
|
||||
//int bbNetPlayerLocal( DPID player );
|
||||
//
|
||||
//int bbSendNetMsg( int type,BBStr *msg,DPID from,DPID to,int reliable );
|
||||
//
|
||||
//int bbRecvNetMsg();
|
||||
//int bbNetMsgType();
|
||||
//BBStr * bbNetMsgData();
|
||||
//DPID bbNetMsgFrom();
|
||||
//DPID bbNetMsgTo();
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,381 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "bbsys.h"
|
||||
#include "resource.h"
|
||||
#include "multiplay_setup.h"
|
||||
|
||||
//IDirectPlay4 *dirPlay;
|
||||
//
|
||||
//struct Connection{
|
||||
// GUID guid;
|
||||
// string name;
|
||||
// void *data;
|
||||
//
|
||||
// Connection( const GUID &g,const string &n,void *d,int sz ):guid(g),name(n){
|
||||
// data=d_new char[sz];memcpy( data,d,sz );
|
||||
// }
|
||||
//
|
||||
// ~Connection(){
|
||||
// delete[] data;
|
||||
// }
|
||||
//};
|
||||
//
|
||||
//struct Session{
|
||||
// GUID guid;
|
||||
// string name;
|
||||
// int max_players,curr_players,data1,data2;
|
||||
//
|
||||
// Session( const DPSESSIONDESC2 *desc ){
|
||||
// guid=desc->guidInstance;
|
||||
// name=string( desc->lpszSessionNameA );
|
||||
// max_players=desc->dwMaxPlayers;
|
||||
// curr_players=desc->dwCurrentPlayers;
|
||||
// data1=desc->dwUser1;data2=desc->dwUser2;
|
||||
// }
|
||||
//};
|
||||
//
|
||||
//static int timer;
|
||||
//static vector<Connection*> connections;
|
||||
//static vector<Session*> sessions;
|
||||
//
|
||||
//static void clearSessions(){
|
||||
// for( ;sessions.size();sessions.pop_back() ) delete sessions.back();
|
||||
//}
|
||||
//
|
||||
//static void clearConnections(){
|
||||
// for( ;connections.size();connections.pop_back() ) delete connections.back();
|
||||
//}
|
||||
//
|
||||
//static bool openDirPlay( HWND hwnd ){
|
||||
// if( dirPlay ) return true;
|
||||
// if( CoCreateInstance( CLSID_DirectPlay,0,CLSCTX_ALL,IID_IDirectPlay4A,(void**)&dirPlay )>=0 ) return true;
|
||||
// MessageBox( hwnd,"Error opening DirectPlay","DirectPlay Error",MB_ICONWARNING );
|
||||
// return false;
|
||||
//}
|
||||
//
|
||||
//static bool closeDirPlay( HWND hwnd ){
|
||||
// if( hwnd && timer ) KillTimer( hwnd,timer );
|
||||
// timer=0;if( !dirPlay ) return true;
|
||||
// dirPlay->Close();
|
||||
// int n=dirPlay->Release();
|
||||
// dirPlay=0;return n==0;
|
||||
//}
|
||||
//
|
||||
//static BOOL FAR PASCAL enumConnection( LPCGUID guid,LPVOID conn,DWORD size,LPCDPNAME name,DWORD flags,LPVOID context ){
|
||||
// IDirectPlay4 *dp;
|
||||
// if( CoCreateInstance( CLSID_DirectPlay,0,CLSCTX_ALL,IID_IDirectPlay4A,(void**)&dp )<0 ) return FALSE;
|
||||
// int n=dp->InitializeConnection( conn,0 );
|
||||
// dp->Release();if( n<0 ) return TRUE;
|
||||
//
|
||||
// Connection *c=d_new Connection( *guid,string( strdup( name->lpszShortNameA ) ),conn,size );
|
||||
// connections.push_back( c );
|
||||
//
|
||||
// return TRUE;
|
||||
//}
|
||||
//
|
||||
//static BOOL FAR PASCAL enumSession( LPCDPSESSIONDESC2 desc,LPDWORD timeout,DWORD flags,LPVOID lpContext ){
|
||||
//
|
||||
// if( !desc ) return FALSE;
|
||||
// sessions.push_back( d_new Session( desc ) );
|
||||
// return TRUE;
|
||||
//}
|
||||
//
|
||||
//static bool startGame( HWND hwnd ){
|
||||
// if( !dirPlay ) return false;
|
||||
//
|
||||
// char buff[MAX_PATH];
|
||||
// int n=GetWindowText( GetDlgItem( hwnd,IDC_GAMENAME ),buff,MAX_PATH );
|
||||
// if( !n ){
|
||||
// MessageBox( hwnd,"Please enter a name for the new game","DirectPlay Request",MB_SETFOREGROUND|MB_TOPMOST|MB_ICONINFORMATION|MB_OK );
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// string name=string( buff )+'\0';
|
||||
//
|
||||
// DPSESSIONDESC2 desc;
|
||||
// memset(&desc,0,sizeof(desc));
|
||||
// desc.dwSize=sizeof(desc);
|
||||
// desc.guidApplication=GUID_NULL;
|
||||
// desc.dwFlags=
|
||||
// DPSESSION_KEEPALIVE|
|
||||
// DPSESSION_MIGRATEHOST|
|
||||
// DPSESSION_NOMESSAGEID|
|
||||
// DPSESSION_OPTIMIZELATENCY|
|
||||
// DPSESSION_DIRECTPLAYPROTOCOL;
|
||||
// desc.lpszSessionNameA=(char*)name.data();
|
||||
//
|
||||
// if( dirPlay->Open( &desc,DPOPEN_CREATE )<0 ){
|
||||
// MessageBox( hwnd,"Unable to create new game","DirPlay Error",MB_ICONWARNING );
|
||||
// return false;
|
||||
// }
|
||||
// return true;
|
||||
//}
|
||||
//
|
||||
//static bool joinGame( HWND hwnd ){
|
||||
// if( !dirPlay ) return false;
|
||||
//
|
||||
// int ses=SendDlgItemMessage( hwnd,IDC_GAMELIST,LB_GETCURSEL,0,0 );
|
||||
// if( ses<0 || ses>=sessions.size() ) return false;
|
||||
//
|
||||
// DPSESSIONDESC2 desc;
|
||||
// memset(&desc,0,sizeof(desc));
|
||||
// desc.dwSize=sizeof(desc);
|
||||
// desc.guidInstance=sessions[ses]->guid;
|
||||
//
|
||||
// if( dirPlay->Open( &desc,DPOPEN_JOIN )<0 ){
|
||||
// MessageBox( hwnd,"Unable to join game","DirPlay Error",MB_ICONWARNING );
|
||||
// return false;
|
||||
// }
|
||||
// return true;
|
||||
//}
|
||||
//
|
||||
//static bool enumSessions( HWND hwnd ){
|
||||
// if( !dirPlay ) return false;
|
||||
//
|
||||
// clearSessions();
|
||||
// EnableWindow( GetDlgItem( hwnd,IDC_GAMELIST ),true );
|
||||
// SendDlgItemMessage( hwnd,IDC_GAMELIST,LB_RESETCONTENT,0,0 );
|
||||
//
|
||||
// DPSESSIONDESC2 desc;
|
||||
// memset(&desc,0,sizeof(desc));
|
||||
// desc.dwSize=sizeof(desc);
|
||||
// desc.guidApplication=GUID_NULL;
|
||||
//
|
||||
// int n=dirPlay->EnumSessions( &desc,0,enumSession,0,DPENUMSESSIONS_ASYNC );
|
||||
// if( n>=0 ){
|
||||
// if( !timer ) SetTimer( hwnd,timer=1,1000,0 );
|
||||
// for( int k=0;k<sessions.size();++k ){
|
||||
// SendDlgItemMessage( hwnd,IDC_GAMELIST,LB_ADDSTRING,0,(LPARAM)strdup( sessions[k]->name.c_str() ) );
|
||||
// }
|
||||
// if( !sessions.size() ){
|
||||
// SendDlgItemMessage( hwnd,IDC_GAMELIST,LB_ADDSTRING,0,(LPARAM)"<no games found>" );
|
||||
// EnableWindow( GetDlgItem( hwnd,IDC_GAMELIST ),false );
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
// closeDirPlay( hwnd );
|
||||
// if( n==DPERR_USERCANCEL ) return false;
|
||||
// MessageBox( hwnd,"Unable to enumerate sessions","DirPlay Error",MB_ICONWARNING );
|
||||
// return false;
|
||||
//}
|
||||
//
|
||||
//static bool connect( HWND hwnd ){
|
||||
// int con=SendDlgItemMessage( hwnd,IDC_CONNECTIONS,CB_GETCURSEL,0,0 );
|
||||
// if( con<1 || con>=connections.size() ) return false;
|
||||
//
|
||||
// closeDirPlay( hwnd );
|
||||
// if( openDirPlay( hwnd ) ){
|
||||
// int n=dirPlay->InitializeConnection( connections[con]->data,0 );
|
||||
// if( n>=0 ){
|
||||
// if( enumSessions( hwnd ) ) return true;
|
||||
// }else{
|
||||
// if( n!=DPERR_USERCANCEL ){
|
||||
// string t="Unable to open "+connections[con]->name;
|
||||
// MessageBox( hwnd,t.c_str(),"DirPlay Error",MB_ICONWARNING );
|
||||
// }
|
||||
// }
|
||||
// closeDirPlay( hwnd );
|
||||
// }
|
||||
// return false;
|
||||
//}
|
||||
//
|
||||
//static void endDialog( HWND hwnd,int rc ){
|
||||
// if( timer ) KillTimer( hwnd,timer );
|
||||
// timer=0;
|
||||
// if( !rc ) closeDirPlay( hwnd );
|
||||
// EndDialog( hwnd,rc );
|
||||
//}
|
||||
//
|
||||
//static BOOL CALLBACK dialogProc( HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam ){
|
||||
//
|
||||
// int k,lo=LOWORD(wparam),hi=HIWORD(wparam);
|
||||
//
|
||||
// bool reset=false;
|
||||
//
|
||||
// switch( msg ){
|
||||
// case WM_INITDIALOG:
|
||||
// SetForegroundWindow( hwnd );
|
||||
// clearConnections();
|
||||
// connections.push_back( d_new Connection( GUID_NULL,"<no connection>","",0 ) );
|
||||
// if( openDirPlay( hwnd ) ){
|
||||
// if( dirPlay->EnumConnections( 0,enumConnection,0,0 )<0 ){
|
||||
// MessageBox( hwnd,"Failed to enumerate connections","DirectPlay Error",MB_SETFOREGROUND|MB_TOPMOST|MB_ICONWARNING|MB_OK );
|
||||
// }
|
||||
// closeDirPlay( hwnd );
|
||||
// }
|
||||
// for( k=0;k<connections.size();++k ){
|
||||
// string t=connections[k]->name;
|
||||
// SendDlgItemMessage( hwnd,IDC_CONNECTIONS,CB_ADDSTRING,0,(LPARAM)t.c_str() );
|
||||
// }
|
||||
// timer=0;
|
||||
// reset=true;
|
||||
// break;
|
||||
// case WM_TIMER: //refresh sessions list!
|
||||
// if( timer && wparam==timer && !enumSessions( hwnd ) ) reset=true;
|
||||
// break;
|
||||
// case WM_CLOSE:
|
||||
// endDialog( hwnd,0 );
|
||||
// break;
|
||||
// case WM_COMMAND:
|
||||
// switch( hi ){
|
||||
// case BN_CLICKED:
|
||||
// switch( lo ){
|
||||
// case IDC_CANCEL:
|
||||
// endDialog( hwnd,0 );
|
||||
// break;
|
||||
// case IDC_GAMENAME:case IDC_HOSTGAME:
|
||||
// if( startGame( hwnd ) ){
|
||||
// endDialog( hwnd,2 );
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
// break;
|
||||
// case LBN_DBLCLK:
|
||||
// switch( lo ){
|
||||
// case IDC_GAMELIST:
|
||||
// if( joinGame( hwnd ) ){
|
||||
// endDialog( hwnd,1 );
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
// break;
|
||||
// case CBN_SELCHANGE:
|
||||
// switch( lo ){
|
||||
// case IDC_CONNECTIONS:
|
||||
// if( connect( hwnd ) ){
|
||||
// EnableWindow( GetDlgItem( hwnd,IDC_GAMENAME ),true );
|
||||
// EnableWindow( GetDlgItem( hwnd,IDC_HOSTGAME ),true );
|
||||
// break;
|
||||
// }else{
|
||||
// reset=true;
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
// break;
|
||||
// default:
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// if( reset ){
|
||||
// closeDirPlay( hwnd );
|
||||
// SendDlgItemMessage( hwnd,IDC_CONNECTIONS,CB_SETCURSEL,0,0 );
|
||||
// EnableWindow( GetDlgItem( hwnd,IDC_GAMELIST ),false );
|
||||
// EnableWindow( GetDlgItem( hwnd,IDC_HOSTGAME ),false );
|
||||
// EnableWindow( GetDlgItem( hwnd,IDC_GAMENAME ),false );
|
||||
// SetWindowText( GetDlgItem( hwnd,IDC_GAMENAME ),"" );
|
||||
// SendDlgItemMessage( hwnd,IDC_GAMELIST,LB_RESETCONTENT,0,0 );
|
||||
// }
|
||||
// return 1;
|
||||
//}
|
||||
//
|
||||
//void multiplay_setup_create(){
|
||||
// dirPlay=0;
|
||||
//}
|
||||
//
|
||||
//void multiplay_setup_destroy(){
|
||||
// multiplay_setup_close();
|
||||
//}
|
||||
//
|
||||
//int multiplay_setup_open(){
|
||||
// gx_runtime->idle();
|
||||
//
|
||||
// int n=DialogBox( GetModuleHandle( "runtime" ),MAKEINTRESOURCE( IDD_MULTIPLAYER ),GetDesktopWindow(),dialogProc );
|
||||
//
|
||||
// if( n!=1 && n!=2 ) n=0;
|
||||
//
|
||||
// clearSessions();
|
||||
// clearConnections();
|
||||
//
|
||||
// //NAUGHTY!
|
||||
// gx_runtime->asyncRun();
|
||||
// gx_runtime->idle();
|
||||
// return n;
|
||||
//}
|
||||
//
|
||||
//void multiplay_setup_close(){
|
||||
// closeDirPlay( 0 );
|
||||
//}
|
||||
//
|
||||
//int multiplay_setup_host( const string &game_name ){
|
||||
// int ret=0;
|
||||
// IDirectPlayLobby *lobby;
|
||||
// IDirectPlayLobby3 *lobby3;
|
||||
// if( CoCreateInstance( CLSID_DirectPlay,0,CLSCTX_ALL,IID_IDirectPlay4A,(void**)&dirPlay )>=0 ){
|
||||
// if( DirectPlayLobbyCreate( 0,&lobby,0,0,0 )>=0 ){
|
||||
// if( lobby->QueryInterface( IID_IDirectPlayLobby3,(void**)&lobby3 )>=0 ){
|
||||
// //ok, create an address for initializeconnection
|
||||
// string ip( "\0" );
|
||||
// char address[256];DWORD sz=256;
|
||||
// if( lobby3->CreateAddress( DPSPGUID_TCPIP,DPAID_INet,ip.data(),ip.size(),address,&sz )>=0 ){
|
||||
// if( dirPlay->InitializeConnection( address,0 )>=0 ){
|
||||
// string name=game_name+'\0';
|
||||
// DPSESSIONDESC2 desc;
|
||||
// memset(&desc,0,sizeof(desc));
|
||||
// desc.dwSize=sizeof(desc);
|
||||
// desc.guidApplication=GUID_NULL;
|
||||
// desc.dwFlags=
|
||||
// DPSESSION_KEEPALIVE|
|
||||
// DPSESSION_MIGRATEHOST|
|
||||
// DPSESSION_NOMESSAGEID|
|
||||
// DPSESSION_OPTIMIZELATENCY|
|
||||
// DPSESSION_DIRECTPLAYPROTOCOL;
|
||||
// desc.lpszSessionNameA=(char*)name.data();
|
||||
// if( dirPlay->Open( &desc,DPOPEN_CREATE )>=0 ){
|
||||
// ret=2;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// lobby3->Release();
|
||||
// }
|
||||
// lobby->Release();
|
||||
// }
|
||||
// if( !ret ){
|
||||
// dirPlay->Release();
|
||||
// dirPlay=0;
|
||||
// }
|
||||
// }
|
||||
// return ret;
|
||||
//}
|
||||
//
|
||||
//int multiplay_setup_join( const string &game_name,const string &ip_add ){
|
||||
// int ret=0;
|
||||
// IDirectPlayLobby *lobby;
|
||||
// IDirectPlayLobby3 *lobby3;
|
||||
// if( CoCreateInstance( CLSID_DirectPlay,0,CLSCTX_ALL,IID_IDirectPlay4A,(void**)&dirPlay )>=0 ){
|
||||
// if( DirectPlayLobbyCreate( 0,&lobby,0,0,0 )>=0 ){
|
||||
// if( lobby->QueryInterface( IID_IDirectPlayLobby3,(void**)&lobby3 )>=0 ){
|
||||
// //ok, create an address for initializeconnection
|
||||
// string ip=ip_add+'\0';
|
||||
// char address[256];DWORD sz=256;
|
||||
// if( lobby3->CreateAddress( DPSPGUID_TCPIP,DPAID_INet,ip.data(),ip.size(),address,&sz )>=0 ){
|
||||
// if( dirPlay->InitializeConnection( address,0 )>=0 ){
|
||||
// DPSESSIONDESC2 desc;
|
||||
// memset(&desc,0,sizeof(desc));
|
||||
// desc.dwSize=sizeof(desc);
|
||||
// desc.guidApplication=GUID_NULL;
|
||||
// if( dirPlay->EnumSessions( &desc,0,enumSession,0,0 )>=0 ){
|
||||
// for( int k=0;k<sessions.size();++k ){
|
||||
// if( sessions[k]->name!=game_name ) continue;
|
||||
// desc.guidInstance=sessions[k]->guid;
|
||||
// if( dirPlay->Open( &desc,DPOPEN_JOIN )>=0 ){
|
||||
// ret=1;
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// clearSessions();
|
||||
// }
|
||||
// }
|
||||
// lobby3->Release();
|
||||
// }
|
||||
// lobby->Release();
|
||||
// }
|
||||
// if( !ret ){
|
||||
// dirPlay->Release();
|
||||
// dirPlay=0;
|
||||
// }
|
||||
// }
|
||||
// return ret;
|
||||
//}
|
||||
@@ -0,0 +1,18 @@
|
||||
|
||||
#ifndef MULTIPLAY_SETUP_H
|
||||
#define MULTIPLAY_SETUP_H
|
||||
|
||||
//#include <dplay.h>
|
||||
//#include <dplobby.h>
|
||||
//
|
||||
//extern IDirectPlay4 *dirPlay;
|
||||
|
||||
//void multiplay_setup_create();
|
||||
//void multiplay_setup_destroy();
|
||||
//
|
||||
//int multiplay_setup_open();
|
||||
//int multiplay_setup_host( const string &game_name );
|
||||
//int multiplay_setup_join( const string &game_name,const string &ip_add );
|
||||
//void multiplay_setup_close();
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,107 @@
|
||||
//Microsoft Developer Studio generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "afxres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// English (U.S.) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
#pragma code_page(1252)
|
||||
#endif //_WIN32
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"#include ""afxres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Dialog
|
||||
//
|
||||
|
||||
IDD_MULTIPLAYER DIALOG DISCARDABLE 0, 0, 190, 199
|
||||
STYLE DS_MODALFRAME | DS_SETFOREGROUND | DS_CENTER | WS_POPUP | WS_VISIBLE |
|
||||
WS_CAPTION | WS_SYSMENU
|
||||
CAPTION "Start Multiplayer Game"
|
||||
FONT 8, "MS Sans Serif"
|
||||
BEGIN
|
||||
PUSHBUTTON "Cancel",IDC_CANCEL,135,178,45,14
|
||||
PUSHBUTTON "Create new game",IDC_HOSTGAME,10,178,67,14
|
||||
EDITTEXT IDC_GAMENAME,10,155,170,12,ES_AUTOHSCROLL |
|
||||
ES_WANTRETURN
|
||||
LISTBOX IDC_GAMELIST,10,53,170,82,LBS_NOINTEGRALHEIGHT |
|
||||
WS_VSCROLL | WS_TABSTOP
|
||||
COMBOBOX IDC_CONNECTIONS,10,22,170,60,CBS_DROPDOWNLIST |
|
||||
WS_VSCROLL | WS_TABSTOP
|
||||
LTEXT "Connection",IDC_STATIC,10,11,170,8
|
||||
LTEXT "Games in progress",IDC_STATIC,10,42,170,8
|
||||
LTEXT "Name for new game",IDC_STATIC,10,144,170,8
|
||||
END
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// DESIGNINFO
|
||||
//
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
GUIDELINES DESIGNINFO DISCARDABLE
|
||||
BEGIN
|
||||
IDD_MULTIPLAYER, DIALOG
|
||||
BEGIN
|
||||
LEFTMARGIN, 10
|
||||
RIGHTMARGIN, 180
|
||||
TOPMARGIN, 11
|
||||
BOTTOMMARGIN, 192
|
||||
END
|
||||
END
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
#endif // English (U.S.) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Developer Studio generated include file.
|
||||
// Used by runtime.rc
|
||||
//
|
||||
#define IDD_MULTIPLAYER 101
|
||||
#define IDC_CANCEL 1011
|
||||
#define IDC_HOSTGAME 1012
|
||||
#define IDC_GAMENAME 1013
|
||||
#define IDC_GAMELIST 1014
|
||||
#define IDC_CONNECTIONS 1015
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 105
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 1021
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
#include "std.h"
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
#ifndef STD_H
|
||||
#define STD_H
|
||||
|
||||
//#ifndef _WINSOCKAPI_
|
||||
//#define _WINSOCKAPI_ /* Prevent inclusion of winsock.h in windows.h */
|
||||
//#endif
|
||||
#include <windows.h>
|
||||
//#include <winsock2.h>
|
||||
|
||||
#include "../config/config.h"
|
||||
#include "../stdutil/stdutil.h"
|
||||
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,34 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "bbsys.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
static vector<HMODULE> _mods;
|
||||
|
||||
static void procNotFound(){
|
||||
RTEX( "User lib function not found" );
|
||||
}
|
||||
|
||||
void _bbLoadLibs( char *p ){
|
||||
while( *p ){
|
||||
HMODULE mod=LoadLibrary( p );
|
||||
if( !mod ){
|
||||
continue;
|
||||
}
|
||||
_mods.push_back(mod);
|
||||
p+=strlen(p)+1;
|
||||
while( *p ){
|
||||
void *proc=GetProcAddress( mod,p );
|
||||
p+=strlen(p)+1;
|
||||
void *ptr=*(void**)p;
|
||||
p+=4;
|
||||
if( !proc ) proc=procNotFound;
|
||||
*(void**)ptr=proc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _bbUnloadLibs(){
|
||||
for( ;_mods.size();_mods.pop_back() ) FreeLibrary( _mods.back() );
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
#ifndef USERLIB_H
|
||||
#define USERLIB_H
|
||||
|
||||
void _bbLoadLibs( char *table );
|
||||
void _bbUnloadLibs();
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,95 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "bbsys.h"
|
||||
#include "userlibs.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
static vector<HMODULE> _mods;
|
||||
|
||||
struct Str{
|
||||
char *p;
|
||||
int size;
|
||||
};
|
||||
|
||||
static Str _strs[256];
|
||||
static int _nextStr;
|
||||
|
||||
static void libNotFound(){
|
||||
ThrowRuntimeException( "User lib not found" );
|
||||
}
|
||||
|
||||
static void procNotFound(){
|
||||
ThrowRuntimeException( "User lib function not found" );
|
||||
}
|
||||
|
||||
void _bbLoadLibs( char *p ){
|
||||
|
||||
string home;
|
||||
|
||||
if( const char *t=getenv( "blitzpath" ) ) home=t;
|
||||
|
||||
while( *p ){
|
||||
HMODULE mod=LoadLibrary( p );
|
||||
if( !mod && home.size() ){
|
||||
mod=LoadLibrary( (home+"/userlibs/"+p).c_str() );
|
||||
}
|
||||
p+=strlen(p)+1;
|
||||
if( mod ){
|
||||
_mods.push_back( mod );
|
||||
while( *p ){
|
||||
void *proc=GetProcAddress( mod,p );
|
||||
p+=strlen(p)+1;
|
||||
void *ptr=*(void**)p;
|
||||
p+=4;
|
||||
*(void**)ptr=proc ? proc : procNotFound;
|
||||
}
|
||||
}else{
|
||||
while( *p ){
|
||||
p+=strlen(p)+1;
|
||||
void *ptr=*(void**)p;
|
||||
p+=4;
|
||||
*(void**)ptr=libNotFound;
|
||||
}
|
||||
}
|
||||
++p;
|
||||
}
|
||||
}
|
||||
|
||||
const char* _bbStrToCStr( BBStr *str ){
|
||||
|
||||
Str &t=_strs[_nextStr++ & 255];
|
||||
|
||||
int size=str->size();
|
||||
|
||||
if( !t.p || t.size<size ){
|
||||
delete[] t.p;
|
||||
t.p=new char[size+1];
|
||||
t.size=size;
|
||||
}
|
||||
|
||||
memcpy( t.p,str->data(),size );
|
||||
t.p[size]=0;
|
||||
delete str;
|
||||
return t.p;
|
||||
}
|
||||
|
||||
BBStr* _bbCStrToStr( const char *str ){
|
||||
return new BBStr( str );
|
||||
}
|
||||
|
||||
bool userlibs_create(){
|
||||
return true;
|
||||
}
|
||||
|
||||
void userlibs_destroy(){
|
||||
for( ;_mods.size();_mods.pop_back() ) FreeLibrary( _mods.back() );
|
||||
}
|
||||
|
||||
void userlibs_link( void(*rtSym)(const char*,void*) ){
|
||||
rtSym( "_bbLoadLibs",_bbLoadLibs );
|
||||
rtSym( "_bbStrToCStr",_bbStrToCStr );
|
||||
rtSym( "_bbCStrToStr",_bbCStrToStr );
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
|
||||
#ifndef USERLIBS_H
|
||||
#define USERLIBS_H
|
||||
|
||||
#include "basic.h"
|
||||
|
||||
void _bbLoadLibs( char *p );
|
||||
|
||||
const char* _bbStrToCStr( BBStr *str );
|
||||
BBStr* _bbCStrToStr( const char *str );
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user