void G_SpawnMap( g_map_t *map, char *path ) { // // load classes // SHV_Printf( " ... planes\n" ); map->planehm = G_MapTryClassLoad( path, MAP_CLASS_NAME_PLANES ); SHV_Printf( " ... mapnodes\n" ); map->mapnodehm = G_MapTryClassLoad( path, MAP_CLASS_NAME_MAPNODES ); SHV_Printf( " ... texdefs\n" ); map->texdefhm = G_MapTryClassLoad( path, MAP_CLASS_NAME_TEXDEFS ); SHV_Printf( " ... textures\n" ); map->texturehm = G_MapTryClassLoad( path, MAP_CLASS_NAME_TEXTURES ); SHV_Printf( " ... visleafs\n" ); map->visleafhm = G_MapTryClassLoad( path, MAP_CLASS_NAME_VISLEAFS ); SHV_Printf( " ... blockmap brushes\n" ); map->blockmaphm = G_MapTryClassLoad( path, MAP_CLASS_NAME_BLOCKMAP ); SHV_Printf( " ... shapes\n" ); map->shapehm = G_MapTryClassLoad( path, MAP_CLASS_NAME_SHAPES ); if ( !map->planehm ) __error( "plane class load failed.\n" ); if ( !map->mapnodehm ) __error( "mapnode class load failed.\n" ); if ( !map->texdefhm ) __error( "texdef class load failed.\n" ); if ( !map->texturehm ) __error( "texture class loaf failed.\n" ); if ( !map->visleafhm ) __error( "visleaf class load failed.\n" ); if ( !map->blockmaphm ) __error( "blockmap class load failed.\n" ); if ( !map->shapehm ) __error( "shape class load failed.\n" ); #if 0 LOGMSG( " volume map ...\n" ); map->volume_ccmap3 = G_MapTryCCMap3Load( path, MAP_CCMAP3_NAME_VOLUME ); LOGMSG( " field map ...\n" ); map->field_ccmap3 = G_MapTryCCMap3Load( path, MAP_CCMAP3_NAME_FIELD ); if ( !map->volume_ccmap3 ) __warning( "volume binary load failed.\n" ); if ( !map->field_ccmap3 ) __warning( "field binary load failed.\n" ); #endif }
const char * SV_AddPlayer( const char *in ) { hobj_t *player_obj; ati_t *player; unique_t id; const char *ptr; char tkn[256]; __named_message( "\n" ); if ( sv_num_player >= SV_MAX_PLAYER ) { __warning( "reached SV_MAX_PLAYER\n" ); return "fail"; } ptr = in; Parse_GetToken( &ptr, tkn, 256 ); if ( !tkn[0] ) { __warning( "missing player id, ignore\n" ); return "fail"; } id = StringToUnique( tkn ); if ( id == UNIQUE_INVALIDE ) { __warning( "player got an invalid id, ignore\n" ); return "fail"; } player = L_AtiSearchById( id ); if ( player ) { __warning( "there is already a player with this id\n" ); return "fail"; } player_obj = NewClass( "player", tkn ); SV_PlayerObjGetNickname( player_obj ); player = ATI_CreatePlayer( player_obj ); L_AtiChangeToWakeUp( player ); sv_num_player++; return "ok"; }
static const char * CL_Com( const char *in ) { char tkn[256]; const char *ptr; const char *result; // __named_message( "get '%s'\n", in ); result = "ok"; ptr = in; Parse_GetToken( &ptr, tkn, 256 ); // printf( "tkn: '%s'\n", tkn ); if ( !tkn[0] ) { } else if ( !strcmp( tkn, "CL_RunFrame" ) ) { result = CL_RunFrame( ptr ); } else if ( !strcmp( tkn, "CL_WorldSpring" ) ) { result = CL_WorldSpring( ptr ); } else { __warning( "can't handle input\n" ); result = "fail"; } return result; }
void GL_GetInfo( gl_info_t *info ) // fill malloced struct { info->extstring = (char*) glGetString( GL_EXTENSIONS ); printf( "%s\n", info->extstring ); if( strstr( info->extstring, "GL_ARB_multitexture" )) { // printf( "arb mulititexture\n" ); __warning( " ***** ignore GL_MAX_TEXTURE_UNITS_ARB *****\n" ); info->texenv_units = 1; // glGetIntegerv( GL_MAX_TEXTURE_UNITS_ARB, &info->texenv_units ); } else { info->texenv_units = 1; } if( strstr( info->extstring, "GL_EXT_texture_env_add" )) { info->texenv_have_add = 1; } else { info->texenv_have_add = 0; } printf( "texunits %d\n", info->texenv_units ); printf( "have add %d\n", info->texenv_have_add ); info->flushinterval = 16; GL_GetSpecialInfo( info ); }
extern void FillAudio( void *udata, Uint8 *stream, int size ) { samplepair_t paintbuf[SST_PAINTBUFSIZE]; int frames; // unsigned char *buf; int pos, i; // __named_message( "\n" ); frames = size / 4; // printf( "frames: %d\n", frames ); if( frames >= SST_PAINTBUFSIZE ) { __warning( "too much data\n" ); return; } #if 1 for( i = 0; i < frames; i++ ) { paintbuf[i].left = paintbuf[i].right = 0; } SND_PaintStereo16( paintbuf, myspec, frames, oldframes ); oldframes = frames; pos = 0; MUS_PaintStereo16( paintbuf, frames ); for( i = 0; i < frames; i++ ) { int left, right; left = paintbuf[i].left; right = paintbuf[i].right; if( left > 0x7fff ) left = 0x7fff; else if( left < (short)0x8000 ) left = (short)0x8000; if( right > 0x7fff ) right = 0x7fff; else if( right < (short)0x8000 ) right = (short)0x8000; *((short*)(&stream[pos])) = (short)left; *((short*)(&stream[pos+2])) = (short)right; pos += 4; } #endif // __named_message( "%d\n", frames ); }
void early_warning(const char *fmt, ...) { va_list ap; va_start(ap, fmt); __warning(NULL, fmt, ap); va_end(ap); }
void main( int argc, char* argv[] ) { char* dumpname; FILE* dumphandle; int dumps; int i; int entryoffs; char id[4]; ca_entry_t entry; unsigned char *buf; char *lmpname; FILE *lmphandle; dumpname = GetCmdOpt( "-d", argc, argv ); if( dumpname == NULL ) __error( "missing arg. no -d\n" ); lmpname = GetCmdOpt( "-e", argc, argv ); dumphandle = fopen( dumpname, "rb" ); __chkptr( dumphandle ); fread( id, 4, 1, dumphandle ); if( !memcmp( id, "CA ", 4 )) __warning( "wrong id in dump.\n" ); fread( &dumps, sizeof( int ), 1, dumphandle ); for( i = 0; i < dumps; i++ ) { fread( &entry, sizeof( ca_entry_t ), 1, dumphandle ); entryoffs = ftell( dumphandle ); printf( "chunk name:\t%s\n", entry.name ); printf( "chunk size:\t%d\n", entry.size ); printf( "chunk pointer:\t%p\n", entry.data ); printf( "data position in dump:\t%d\n\n", entryoffs ); if( lmpname ) if( !strcmp( lmpname, entry.name ) ) { printf( "extracting lump to lump\n" ); buf = ( unsigned char* )malloc( entry.size ); __chkptr( buf ); fread( buf, entry.size, 1, dumphandle ); lmphandle = fopen( "lump", "wb" ); fwrite( buf, entry.size, 1, lmphandle ); free( buf ); fclose( lmphandle ); } else { fseek( dumphandle, entry.size, SEEK_CUR ); } } fclose( dumphandle ); }
void U_UnpackSkip( int space ) { if( cur_size + space >= cur_maxsize ) { __warning( "running out of input buffer\n" ); } cur_pos += space; cur_size += space; }
void SST_ShutDown() { if( !isup ) { __warning( "sst is not up\n" ); return; } SDL_CloseAudio(); }
/* ============================== SV_RemovePlayer ============================== */ const char * SV_RemovePlayer( const char *in ) { ati_t *player; unique_t id; const char *ptr; char tkn[256]; __named_message( "\n" ); ptr = in; Parse_GetToken( &ptr, tkn, 256 ); if ( !tkn[0] ) { __warning( "missing player id, ignore\n" ); return "fail"; } id = StringToUnique( tkn ); if ( id == UNIQUE_INVALIDE ) { __warning( "player got an invalid id, ignore\n" ); return "fail"; } player = L_AtiSearchById( id ); if ( !player ) { __warning( "no server object '#%u' found\n", id ); return "fail"; } SV_PlayerObjReleaseNickname( player->ati_obj ); L_AtiChangeToDead( player ); sv_num_player--; return "ok"; }
void RejectLife() { __named_message( "\n" ); if( lloaded ) { le.L_ShutDown(); SYS_DllEnd( lhandle ); SHV_Printf( "life killed.\n" ); } else __warning( "no dll loaded\n" ); lloaded = 0; }
void SHM_DrawPage( hobj_t *page ) { int i; char entryname[256]; shm_funcmap_t *map; hpair_t *pair; hobj_t *entry; // hobj_search_iterator_t *iter; pair = FindHPair( page, "active" ); __chkptr( pair ); i = 255; for( ; ; ) { sprintf( entryname, "%d", i ); entry = FindClass( page, entryname ); if( !entry ) { if( i >= 255 ) { i = 0; continue; } else { break; } } map = SHM_LookupFuncmap( entry->type ); if( !map ) { __warning( "unknown widget type '%s'\n", entry->type ); continue; } if( !map->drawfunc ) __error( "no drawfunc for '%s'\n", entry->type ); if( !strcmp( pair->value, entry->name ) ) { map->drawfunc( entry, 1 ); } else map->drawfunc( entry, 0 ); i++; } }
void Util_AtiRegisterId( cl_ati_t *ati ) { cl_ati_t *search; search = (cl_ati_t *) U_MapSearch( &cl_id_to_ati_map, (void *) &ati->id ); if ( search ) { __warning( "there is already an ati with id '#%u', ignore register\n", ati->id ); } else { U_MapInsert( &cl_id_to_ati_map, (void *) ati ); } }
/* ============================== L_SwitchMapRemoveSwitchAble ============================== */ void L_SwitchMapRemoveSwitchAble( ati_t *self ) { int i; for ( i = 0; i < L_SWITCHMAP_MAX_OBJECTS; i++ ) { if ( l_switchmap_owners[i] == self ) { l_switchmap_owners[i] = NULL; return; } } __warning( "archetype not found in switchmap\n" ); }
void L_ChangeToRun( ati_t *at ) { // only a wakeup state can change to run state if ( at->state != ATIState_wakeup ) { __warning( "ignore state change to 'run', current state is not 'wakeup'\n" ); return; } if ( at->prev && at->next ) { L_UnlinkAT( at ); } at->state = ATIState_run; L_ATListInsertAtHead( &l_run, at ); }
hmanager_t * NewFlatHManagerFromClass( hobj_t *root ) { hmanager_t *hm; hm = (hmanager_t *) malloc( sizeof( hmanager_t ) ); memset( hm, 0, sizeof( hmanager_t ) ); hm->root = root; if ( !hm->root ) { __warning( "null class.\n" ); return NULL; } HManagerRebuildHash( hm ); return hm; }
void jpeg_ibase_src( j_decompress_ptr cinfo, ib_file_t *h ) { my_src_ptr src; if( cinfo->src != NULL ) { __warning( "cinfo->src != NULL\n" ); } cinfo->src = (struct jpeg_source_mgr *) NEWTYPE( my_source_mgr ); src = (my_src_ptr) cinfo->src; src->pub.init_source = init_source; src->pub.fill_input_buffer = fill_input_buf; src->pub.skip_input_data = skip_input_data; src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */ src->pub.term_source = term_source; src->h = h; src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */ src->pub.next_input_byte = NULL; /* until buffer loaded */ }
METHODDEF( boolean )fill_input_buf( j_decompress_ptr cinfo ) { my_src_ptr src = (my_src_ptr) cinfo->src; int num, i, c; __named_message( "\n" ); if( !src->h ) { __warning( "handle == NULL.\n" ); // very faky. src->buffer[0] = (JOCTET) 0xFF; src->buffer[1] = (JOCTET) JPEG_EOI; num = 2; } for( i = 0; i < INPUT_BUF_SIZE; i++ ) { c = IB_GetChar( src->h ); // printf( "%d\n", c ); if( c == EOF ) { break; } src->buffer[i] = c; } num = i; src->pub.next_input_byte = src->buffer; src->pub.bytes_in_buffer = num; return TRUE; }
void LA_InsertVarview( const char *varname, void (* callback )( int flag, char *string )) { int i; sh_var_t *var; for( i = 0; i < LA_VARVIEWNUM; i++ ) { if( !la_varviews[i].var ) break; } if( i >= LA_VARVIEWNUM ) { __warning( "no free varwiew\n" ); return; } var = SHP_GetVar( varname ); la_varviews[i].var = var; la_varviews[i].callback = callback; }
/* ============================== UnpackEventSwitch ============================== */ static void UnpackEventSwitch( cl_ati_t *atif, unique_t id, eventType type, byte_iter_t *bi ) { cl_at_switch_t *_switch; _switch = ADDR_OF_BASE( cl_at_switch_t, atif, atif ); if ( _switch->ev_valid ) { // __warning( "override event\n" ); } if ( type == eventType_client_obj_update_state ) { _switch->ev_state = ByteIter_Unpacki( bi ); } else { __warning( "unkown event for client object '#%u'\n", id ); } _switch->ev_valid = true; }
/* ============================== UnpackEventItem ============================== */ static void UnpackEventItem( cl_ati_t *atif, unique_t id, eventType type, byte_iter_t *bi ) { cl_at_item_t *item; // __named_message( "\n" ); item = ADDR_OF_BASE( cl_at_item_t, atif, atif ); if ( type == eventType_client_obj_update_pos ) { ByteIter_Unpack3fv( bi, item->origin ); } else if ( type == eventType_client_obj_update_style ) { itemStyle style; style = (itemStyle)ByteIter_Unpacki( bi ); if ( style != item->style ) { item->style = style; if ( item->style == itemStyle_rocket ) { item->ri_model.md = CL_CreateModelFromResourceName( "rocket1" ); CL_ModelSetMoveByName( item->ri_model.md, "base_frame" ); } else if ( item->style == itemStyle_rlaunch ) { item->ri_model.md = CL_CreateModelFromResourceName( "rlaunch1" ); CL_ModelSetMoveByName( item->ri_model.md, "base_frame" ); } else { __error( "unknown item style '%d'\n", item->style ); } } } else { __warning( "unkown event for client object '#%u'\n", id ); } }
void SHM_UpdatePage( hobj_t *page, keyevent_t *e, int active ) { char text[256]; hobj_t *entry; shm_funcmap_t *map; sprintf( text, "%d", active ); entry = FindClass( page, text ); map = SHM_LookupFuncmap( entry->type ); if( !map ) { __warning( "unknown widget type '%s'\n", entry->type ); return; } if( !map->updatefunc ) __error( "no updatefunc for '%s'\n", entry->type ); map->updatefunc( entry, e ); }
void SND_StartUp() { ALuint sources[SND_MAX_SRCNUM]; int i; /* int attr[] = { ALC_FREQUENCY, 22050, 0 }; */ if( sst_isup ) { __warning( "sound is already up\n" ); return; } if( !((sh_var_t *)SHP_GetVar( "sound" ))->ivalue ) { __named_message( "\tsound disabled\n" ); sst_isup = 0; return; } Vec3dInit( snd_origin, 0.0, 0.0, 0.0 ); alc_ctx = alcCreateContext( NULL ); alcMakeContextCurrent( alc_ctx ); // init listener alListenerfv( AL_POSITION, zeroes ); alListenerfv( AL_VELOCITY, zeroes ); { alListenerfv( AL_ORIENTATION, front ); } // init sources memset( srcs, 0, SND_MAX_SRCNUM * sizeof( snd_source_t )); al_srcnum = alGenSources( SND_MAX_SRCNUM, sources ); if( al_srcnum != SND_MAX_SRCNUM ) { __warning( "got only %d sources\n", al_srcnum ); } for( i = 0; i < al_srcnum; i++ ) { srcs[i].al_source = sources[i]; printf( "source %d: %d\n", i, srcs[i].al_source ); // alSource3f( srcs[i].al_source, AL_POSITION, 0.0, 0.0, 0.0 ); } alAttenuationScale( 0.7 ); snd_num = 0; sst_isup = 1; // if( 1 ) { ALuint sources[2]; ALuint boom, l2; ALsizei size; ALsizei bits; ALsizei freq; ALsizei format; void *wave = NULL; ALuint left = 0; ALuint right = 0; __named_message( "test...\n" ); if( alGenBuffers( 1, &boom ) != 1 ) { fprintf( stderr, "aldemo: couldn't generate buffers\n" ); exit( 1 ); } alutLoadWAV( "boom.wav", &wave, &format, &size, &bits, &freq); alBufferData( boom, format, wave, size, freq ); alSource3f( boom, AL_POSITION, -5.0, 0.0, 0.0 ); alSourcefv( boom, AL_VELOCITY, zeroes ); alSourcefv( boom, AL_ORIENTATION, back ); alSourcei( boom, AL_BUFFER, boom ); alSourcei( boom, AL_LOOPING, AL_FALSE ); alSourcePlay( boom ); alAttenuationScale(0.7); } }
int SND_AddJob( g_resource_t *res, int type, int pri, vec3d_t origin ) { res_sound_cache_t *s; int i; ALuint src; if( !sst_isup ) { return 0; } s = res->res_cache; if( !s ) { __warning( "snd->res_cache == NULL\n" ); return 0; } if( !pri ) { __warning( "no priority. failed\n" ); return 0; } // search for free source for( i = 0; i < al_srcnum; i++ ) { if( !srcs[i].inuse ) break; } if( i >= al_srcnum ) // none free => drop less priority sound { for( i = 0; i < al_srcnum; i++ ) { if( srcs[i].pri < pri ) break; } } if( i >= al_srcnum ) // even none => drop equal priority { for( i = 0; i < al_srcnum; i++ ) { if( srcs[i].pri == pri ) break; } } if( i >= al_srcnum ) // even none => drop equal priority { __warning( "no free source\n" ); return 0; } snd_num++; // must be > 0 srcs[i].inuse = 1; srcs[i].id = snd_num; srcs[i].pri = pri; src = srcs[i].al_source; // alSourcefv( src, AL_POSITION, origin ); alSource3f( src, AL_POSITION, -5.0, 0.0, 0.0 ); alSourcefv( src, AL_VELOCITY, zeroes ); alSourcefv( src, AL_ORIENTATION, back ); // alSourcef( src, AL_GAIN, 1.0 ); #if 0 if( s->al_buf == 0 ) { __error( "al_buf == 0, %s\n", (char * )res->res_register ); } #endif // SHV_Printf( "playing %d\n", s->al_buf ); alSourcei( src, AL_BUFFER, s->al_buf ); alSourcei( src, AL_LOOPING, AL_FALSE ); alSourcePlay( src ); return snd_num; }
void main( int argc, char* argv[] ) { u_int32_t i, i2, arrcount; int x, y, xs, ys, xh, yh; char dumpheaders = 0; char* tganame; char* arrname; char* palname; char* arrident; char* arrnext; char* arrmode; int reducemode; int mm; int ts, td; int pixels; int rsum, gsum, bsum; int x2, y2; int blur; FILE* tgahandle; FILE* arrhandle; FILE* palhandle; pal_t* pal = NULL; tga_t* tga[2]; arr_t* arr; rgb_t rgb; dumpheaders = CheckCmdSwitch( "-d", argc, argv ); palname = GetCmdOpt( "-p", argc, argv ); tganame = GetCmdOpt( "-t", argc, argv ); if( tganame == NULL ) { printf( "no tga given.\n" ); PrintUsage(); exit( 0 ); } if ( CheckCmdSwitch( "--rgb565", argc, argv ) ) { reducemode = ARR_F_RGB565; } else { reducemode = ARR_F_P8; } arrident = GetCmdOpt( "-i", argc, argv ); if( arrident == NULL ) __warning( "no arr ident given.\n" ); else if( strlen( arrident ) >= 32 ) arrident[31] = '\0'; printf( "tga: %s\n", tganame ); tgahandle = fopen( tganame, "rb" ); CHKPTR( tgahandle ); tga[0] = TGA_Read( tgahandle ); CHKPTR( tga[0] ); // TGA_Dump( tga[0] ); fclose( tgahandle ); if( dumpheaders ) TGA_Dump( tga[0] ); tga[1] = TGA_Create( tga[0]->image_width/*/2*/, tga[0]->image_height/*/2*/, TGA_TYPE_TRUECOLOR ); __chkptr( tga[1] ); arrname = GetCmdOpt( "-a", argc, argv ); if( arrname == NULL ) { printf( "no arr given.\n" ); PrintUsage(); exit( 0 ); } printf( "arr: %s\n", arrname ); switch( tga[0]->image_type ) { case TGA_TYPE_TRUECOLOR: printf( "tga is 24bit.\n" ); if( palname == NULL ) { CDB_StartUp( 0 ); palname = CDB_GetString( "misc/default_pal" ); if( palname == NULL ) { PrintUsage(); __error( "no pal found.\n" ); } } printf( "pal: %s\n", palname ); palhandle = fopen( palname, "rb" ); CHKPTR( palhandle ); pal = PAL_Read( palhandle ); CHKPTR( pal ); fclose( palhandle ); arr = ARR_Create( tga[0]->image_width, tga[0]->image_height, 4, 1, arrident, reducemode ); CHKPTR( arr ); printf( "reducing color. " ); xs = tga[0]->image_width; ys = tga[0]->image_height; arrcount = 0; for ( mm = 0; mm < 4; mm++ ) { ts = mm & 1; td = (mm+1) & 1; // printf("%d->%d\n",ts,td); // reduce // printf(" i: %d, x: %d, y: %d\n", mm, xs, ys ); pixels = xs * ys; for( i = 0; i < pixels; i++ ) { rgb.red = tga[ts]->image.red[i]; rgb.green = tga[ts]->image.green[i]; rgb.blue = tga[ts]->image.blue[i]; if ( reducemode == ARR_F_P8 ) arr->data[arrcount++] = PAL_ReduceColor( pal, &rgb ); else { *((unsigned short*)(&arr->data[arrcount])) = RGB888ToRGB565( &rgb ); arrcount+=2; } if( (i & 0xff) == 0 ) { printf( "." ); fflush( stdout ); } } if ( mm == 3 ) break; // mipmap xh = xs / 2; yh = ys / 2; if ( xh < 4 || yh < 4 ) blur = 0; else blur = 1; for ( y = 0; y < yh; y++ ) { for ( x = 0; x < xh; x++ ) { x2 = x*2; y2 = y*2; if ( blur ) { rsum = tga[ts]->image.red[ y2*xs + x2 ]; gsum = tga[ts]->image.green[ y2*xs + x2 ]; bsum = tga[ts]->image.blue[ y2*xs + x2 ]; rsum += tga[ts]->image.red[ y2*xs + (x2+1) ]; gsum += tga[ts]->image.green[ y2*xs + (x2+1) ]; bsum += tga[ts]->image.blue[ y2*xs + (x2+1) ]; rsum += tga[ts]->image.red[ (y2+1)*xs + x2 ]; gsum += tga[ts]->image.green[ (y2+1)*xs + x2 ]; bsum += tga[ts]->image.blue[ (y2+1)*xs + x2 ]; rsum += tga[ts]->image.red[ (y2+1)*xs + (x2+1) ]; gsum += tga[ts]->image.green[ (y2+1)*xs + (x2+1) ]; bsum += tga[ts]->image.blue[ (y2+1)*xs + (x2+1) ]; tga[td]->image.red[ y*xh + x ] = rsum / 4; tga[td]->image.green[ y*xh + x ] = gsum / 4; tga[td]->image.blue[ y*xh + x ] = bsum / 4; } else { rsum = tga[ts]->image.red[ y2*xs + x2 ]; gsum = tga[ts]->image.green[ y2*xs + x2 ]; bsum = tga[ts]->image.blue[ y2*xs + x2 ]; tga[td]->image.red[ y*xh + x ] = 255; //rsum; tga[td]->image.green[ y*xh + x ] = 0;//gsum; tga[td]->image.blue[ y*xh + x ] = 0; //bsum; } } } xs = xh; ys = yh; } printf( "\n" ); break; /* case TGA_TYPE_INDEXED: printf( "tga is indexed./n" ); arr = ARR_Create( tga->image_width, tga->image_height, 1, arr_ident, NULL ); CHKPTR( arr ); printf( "copying ...\n" ); memcpy( arr->data, tga->image_indexed.data, tga->image_indexed.bytes ); break; */ default: __error( "we need an uncompressed 24(/8)bit tga.\n" ); ARR_Free( arr ); break; } arrhandle = fopen( arrname, "wb" ); CHKPTR( arrhandle ); ARR_Write( arrhandle, arr ); fclose( arrhandle ); }
shape_t * R_SetupCSurfShape( hobj_t *shape, g_map_t *map ) { #if 1 int i, u, v; hobj_t *multilayer; hobj_t *csurf; hpair_t *pair; shape_t *shp; int upointnum; int vpointnum; multilayer = NULL; csurf = FindClassType( shape, "csurf" ); if ( !csurf ) __error( "missing class 'csurf' in shape '%s'\n", shape->name ); // get control points EasyFindInt( &upointnum, csurf, "upointnum" ); EasyFindInt( &vpointnum, csurf, "vpointnum" ); Shape_BeginInstance(); Shape_SetPrimaryKey( StringToUnique( shape->name ) ); Shape_SetTesselation( ShapeTesselation_curved_surface ); Shape_SetCtrlPointNum( upointnum, vpointnum ); for ( u = 0; u < upointnum; u++ ) { for ( v = 0; v < vpointnum; v++ ) { vec3d_t p; char str[256]; sprintf( str, "u%d_v%d", u, v ); EasyFindVec3d( p, csurf, str ); Shape_AddCtrlPoint( Shape_NewCtrlPointUV3fv( u, v, p ) ); } } // // texture layer // if ( 1 ) { hobj_t *texdef0; vec2d_t vecs[4]; vec2d_t scale; g_resource_t *gltex_res; char str[256]; layer_t *layer; unitex_t *uni; texdef0 = FindClassType( shape, "uv_texdef0" ); if ( !texdef0 ) __error( "missing class 'uv_texdef0' in shape '%s'\n", shape->name ); EasyFindVec2d( vecs[0], texdef0, "shift" ); EasyFindVec2d( vecs[1], texdef0, "vec2" ); EasyFindVec2d( vecs[2], texdef0, "vec0" ); EasyFindVec2d( vecs[3], texdef0, "vec1" ); EasyFindVec2d( scale, texdef0, "scale" ); for ( i = 1; i < 4; i++ ) { vecs[i][0] *= scale[0]; vecs[i][1] *= scale[1]; } Vec2dAdd( vecs[1], vecs[1], vecs[0] ); Vec2dAdd( vecs[2], vecs[2], vecs[0] ); Vec2dAdd( vecs[3], vecs[3], vecs[0] ); pair = FindHPair( texdef0, "ident" ); if ( !pair ) __error( "missing key 'ident' in texdef class '%s'\n", texdef0->name ); // // check ident for multilayer definition // { multilayer = HManagerSearchClassName( map->multilayerhm, pair->value ); if ( multilayer ) { __named_message( "MULTILAYER DEFINITON !\n" ); R_SetupCSurfMultiLayerFromClass( texdef0, multilayer ); goto skip_texture; } } // build gltex resource name from ident sprintf( str, "gltex.%s", pair->value ); strcrpl( str, '/', '.' ); gltex_res = G_ResourceSearch( g_rs, str ); uni = UniTex_NewFrom_gltexres( gltex_res ); Layer_BeginInstance( (layerMode)(LayerMode_uv | LayerMode_Texel0N) ); { // hack: build layer_gl_state_t layer_gl_state_t *glstate; glstate = NEWTYPE( layer_gl_state_t ); glstate->flags |= LAYER_STATE_FLAGS_DEPTH_MASK; glstate->sfactor = GL_ONE; glstate->dfactor = GL_ZERO; Layer_SetGLstate( glstate ); } Layer_SetOrdinal( LAYER_TEXTURE_1 ); Layer_SetUniTex( uni ); Layer_SetUVCtrl( vecs ); layer = Layer_EndInstance(); Shape_AddLayer( layer ); } skip_texture: // // diffuse layer // #if 1 { hobj_t *lightdef; int width; int height; ic_subimage_t *sub; unitex_t *uni; lightmap_t *lightmap_head; layer_t *layer; lightdef = FindClassType( shape, "uv_lightdef" ); if ( !lightdef ) { goto no_lightdef; } EasyFindInt( &width, lightdef, "width" ); EasyFindInt( &height, lightdef, "height" ); lightmap_head = LinkLightmaps( a_map->lightmap_db, StringToUnique( shape->name ), 0 ); if ( !lightmap_head && 0 ) goto no_diffuse; // setup diffuse lightmap { int lightmap_bytes; void *lightmap_pixels; lightmap_bytes = width*height*4; lightmap_pixels = NEWBYTES( lightmap_bytes ); sub = IC_NewSubImage( width, height ); IC_SubImageSetPixels( sub, lightmap_pixels ); } uni = UniTex_NewFrom_subimage( sub ); // create diffuse layer Layer_BeginInstance( (layerMode)(LayerMode_uv | LayerMode_Texel01) ); { // hack: build layer_gl_state_t layer_gl_state_t *glstate; glstate = NEWTYPE( layer_gl_state_t ); glstate->flags |= LAYER_STATE_FLAGS_DEPTH_MASK; glstate->sfactor = GL_ZERO; glstate->dfactor = GL_SRC_COLOR; Layer_SetGLstate( glstate ); } Layer_SetOrdinal( LAYER_DIFFUSE_1 ); Layer_SetUniTex( uni ); Layer_SetLightmapHead( lightmap_head ); { int i; vec2d_t vecs[4] = { {0,0},{1,0},{0,1},{1,1} }; // shrink and shift for lightmap boarders for ( i = 0; i < 4; i++ ) { vecs[i][0] *= (width*1.0)/(width+1.0); vecs[i][1] *= (height*1.0)/(height+1.0); vecs[i][0] += 0.5/(width*1.0); vecs[i][1] += 0.5/(height*1.0); } Layer_SetUVCtrl( vecs ); } layer = Layer_EndInstance(); Shape_AddLayer( layer ); no_diffuse: {} } #endif // // specular layer // #if 1 { hobj_t *lightdef; int width; int height; ic_subimage_t *sub; unitex_t *uni; layer_t *layer; lightmap_t *lightmap_head; lightdef = FindClassType( shape, "uv_lightdef" ); if ( !lightdef ) { goto no_lightdef; } EasyFindInt( &width, lightdef, "width" ); EasyFindInt( &height, lightdef, "height" ); lightmap_head = LinkLightmaps( a_map->lightmap_db, StringToUnique( shape->name ), 1 ); if ( !lightmap_head ) goto no_specular; // setup specular lightmap { int lightmap_bytes; void *lightmap_pixels; lightmap_bytes = width*height*4; lightmap_pixels = NEWBYTES( lightmap_bytes ); sub = IC_NewSubImage( width, height ); IC_SubImageSetPixels( sub, lightmap_pixels ); } uni = UniTex_NewFrom_subimage( sub ); // create specular layer Layer_BeginInstance( (layerMode)(LayerMode_uv | LayerMode_Texel01) ); { // hack: build layer_gl_state_t layer_gl_state_t *glstate; glstate = NEWTYPE( layer_gl_state_t ); glstate->flags |= LAYER_STATE_FLAGS_DEPTH_MASK; glstate->sfactor = GL_ONE; glstate->dfactor = GL_ONE; Layer_SetGLstate( glstate ); } Layer_SetOrdinal( LAYER_SPECULAR_1 ); Layer_SetUniTex( uni ); Layer_SetLightmapHead( lightmap_head ); { int i; vec2d_t vecs[4] = { {0,0},{1,0},{0,1},{1,1} }; // shrink and shift for lightmap boarders for ( i = 0; i < 4; i++ ) { vecs[i][0] *= (width*1.0)/(width+1.0); vecs[i][1] *= (height*1.0)/(height+1.0); vecs[i][0] += 0.5/(width*1.0); vecs[i][1] += 0.5/(height*1.0); } Layer_SetUVCtrl( vecs ); } layer = Layer_EndInstance(); Shape_AddLayer( layer ); no_specular: {} } #endif no_lightdef: shp = Shape_EndInstance(); if ( multilayer ) { hobj_t *mesh_obj; hobj_search_iterator_t iter; hobj_t *job; int multi_flags; mesh_obj = FindClassType( multilayer, "mesh" ); if ( mesh_obj ) { InitClassSearchIterator( &iter, mesh_obj, "job" ); for ( ; ( job = SearchGetNextClass( &iter ) ) ; ) { if ( !strcmp( job->name, "SurfaceDeform" ) ) { R_RegisterShapeCtrlJob( ShapeCtrlJob_Create_SurfaceDeform( job, shp ) ); } else { __warning( "unknown ShapeCtrlJob '%s', ignore it\n", job->name ); } } } multi_flags = LAYER_STATE_FLAGS_DEPTH_MASK; pair = FindHPair( multilayer, "depthmask" ); if ( !pair ) { // default is depthmask = true multi_flags |= LAYER_STATE_FLAGS_DEPTH_MASK; } else { if ( !strcmp( pair->value, "0" ) ) { multi_flags &= ~LAYER_STATE_FLAGS_DEPTH_MASK; multi_flags |= LAYER_STATE_FLAGS_SHADE_P3; } else { multi_flags |= LAYER_STATE_FLAGS_DEPTH_MASK; } } { u_list_iter_t iter; layer_t *layer; U_ListIterInit( &iter, shp->layer_list ); for ( ; ( layer = (layer_t *)U_ListIterNext( &iter ) ) ; ) { layer->glstate->flags = multi_flags; } } } return shp; #else return NULL; #endif }
/* ============================== SV_RunFrame ============================== */ const char * SV_RunFrame( const char *in ) { int num_sleep, num_wakeup, num_dead; int num_think1, num_think2; ati_t *ati, *next; char tkn[256]; const char *tkn_ptr; TFUNC_ENTER; // // get current frame time // tkn_ptr = in; Parse_GetToken( &tkn_ptr, tkn, 256 ); if ( !tkn[0] ) { __warning( "missing current time in call\n" ); TFUNC_LEAVE; return "fail"; } else { sv_time_last_frame = sv_time_current_frame; sv_time_current_frame = atoi( tkn ); if ( sv_time_current_frame <= sv_time_last_frame ) { __warning( "current time < last time\n" ); TFUNC_LEAVE; return "fail"; } else { sv_time_delta_frame = sv_time_current_frame-sv_time_last_frame; sv_delta_sec = sv_time_delta_frame/1000.0; } } #if 0 __named_message( "times: last %d, current %d, delta %d\n", sv_time_last_frame, sv_time_current_frame, sv_time_delta_frame ); #endif if ( sv_delta_sec > 0.5 ) { __warning( "clip server frame time delta !!!\n" ); sv_delta_sec = 0.5; } sv_time = sv_time_current_frame; sv_time_delta = sv_delta_sec; // // send server frame time info to client // { byte_iter_t frm; PackFrame_Begin( bi_out, &frm ); ByteIter_Packi( &frm, UNIQUE_INVALIDE ); ByteIter_Packi( &frm, eventType_client_info_time ); ByteIter_Packi( &frm, sv_time_last_frame ); ByteIter_Packi( &frm, sv_time_current_frame ); PackFrame_End( bi_out, &frm ); } // // dispatch all events in the input buffer // { int remain; for(;;) { byte_iter_t frm; unique_t id; eventType ev_type; remain = ByteIter_GetSize( bi_in ) - ByteIter_GetOfs( bi_in ); if ( remain == 0 ) break; /*frm_size = */UnpackFrame_Begin( bi_in, &frm ); id = ByteIter_Unpacki( &frm ); ev_type = (eventType)ByteIter_Unpacki( &frm ); if ( ev_type < eventType_server_first || ev_type > eventType_server_last ) { __error( "not a 'server' event\n" ); } ati = L_AtiSearchById( id ); if ( !ati ) { __warning( "no server object for id '#%u' found\n", id ); } else { if ( !ati->ftbl->UnpackEvent ) { __error( "server object '#%u' has no ability to unpack events\n" ); } else { ati->ftbl->UnpackEvent( ati, id, ev_type, &frm ); } } UnpackFrame_End( bi_in, &frm ); } } // // first move all archetypes from the wakeup_list to the run_list // num_wakeup = 0; for ( ; ( ati = L_AtiListRemoveAtHead( &sv_wakeup ) ) ; ) { L_AtiChangeToRun( ati ); num_wakeup++; } // // all archetypes in the run_list Think1 now // // L_BeginCollideMap(); num_think1 = 0; num_think2 = 0; L_CollideMapReset(); for ( ati = sv_run.head.next ; ati != &sv_run.tail ; ati = next ) { // archetypes may change to sleep_list or dead_list next = ati->next; if ( ati->ftbl->Run ) { ati->ftbl->Run( ati, atiRun_think1 ); num_think1++; } } for ( ati = sv_run.head.next ; ati != &sv_run.tail ; ati = next ) { // archetypes may change to sleep_list or dead_list next = ati->next; if ( ati->ftbl->Run ) { ati->ftbl->Run( ati, atiRun_think2 ); num_think2++; } } // // finally destroy all archetypes in the dead_list // num_dead = 0; for ( ; ( ati = L_AtiListRemoveAtHead( &sv_dead ) ) ; ) { ati->ftbl->Destroy( (ati_t*)ati ); num_dead++; } // // count sleeping archetypes // num_sleep = 0; for ( ati = sv_sleep.head.next ; ati != &sv_sleep.tail ; ati=ati->next ) { num_sleep++; } // printf( " life: %d sleeps, %d wakeups, %d t1, %d t2, %d deads\n", num_sleep, num_wakeup, num_think1, num_think2, num_dead ); sv_frame_count++; TFUNC_LEAVE; return "ok"; }
void R_BE_ProcessCMDBuffer( void ) { int i, j; int num; int cmd, *ptr, *end; vec4d_t *va; static int glflush_hack = 0; #if 0 if ( be_va_locked == false ) { __warning( "vertex array not locked\n" ); return; } if ( !be_cmds ) { __warning( "null command buffer\n" ); return; } if ( be_cmdnum == 0 ) { __warning( "empty command buffer\n" ); return; } if ( !be_vrefs ) { __warning( "null vertex reference buffer\n" ); return; } if ( be_vrefnum == 0 ) { __warning( "empty vertex reference buffer\n" ); return; } if ( be_colors && ( be_colornum != be_vrefnum ) ) { __warning( "colornum != vrefnum\n" ); return; } if ( be_texcoords && ( be_texcoordnum != be_vrefnum ) ) { __warning( "texcoordnum != vrefnum\n" ); return; } // if ( be_vertexnum > 0 ) { glVertexPointer( 4, GL_FLOAT, 0, be_va ); // glEnableClientState( GL_VERTEX_ARRAY ); } // else // { // return; // } if ( be_colors ) { glColorPointer( 3, GL_FLOAT, 0, be_colors ); // glEnableClientState( GL_COLOR_ARRAY ); } if ( be_texcoords ) { glTexCoordPointer( 2, GL_FLOAT, 0, be_texcoords ); // glEnableClientState( GL_TEXTURE_COORD_ARRAY ); } #endif va = &be_va[be_vofs]; i = 0; ptr = be_cmds; end = &be_cmds[be_cmdnum]; for(;;) { if ( ptr >= end ) __error( "reached command buffer end\n" ); cmd = *ptr++; #if 1 if ( cmd != BE_CMD_END ) { num = *ptr++; if ( glcmd_lut[cmd] == GL_TRIANGLE_FAN ) { COUNT_ADD( count_be_num_tri, num-2 ); } else if ( glcmd_lut[cmd] == GL_TRIANGLE_STRIP ) { COUNT_ADD( count_be_num_tri, num-2 ); } else if ( glcmd_lut[cmd] == GL_TRIANGLES ) { COUNT_ADD( count_be_num_tri, num/3 ); } else if ( glcmd_lut[cmd] == GL_POLYGON ) { COUNT_ADD( count_be_num_tri, num-2 ); } glBegin( glcmd_lut[cmd] ); COUNT_INCR( count_be_num_begin ); for ( j = 0; j < num; j++, i++ ) { if ( be_colors ) glColor3fv( be_colors[i] ); if ( be_texcoords ) glTexCoord2fv( be_texcoords[i] ); glVertex4fv( va[be_vrefs[i]] ); // glArrayElement( i+be_vofs ); } glEnd(); if ( glflush_hack >= r_glinfo->flushinterval ) { // printf( "%d\n", r_glinfo->flushinterval ); glFlush(); COUNT_INCR( count_be_num_flush ); glflush_hack = 0; } else glflush_hack++; } else { break; } #else #endif } #if 0 if ( glflush_hack >= r_glinfo->flushinterval ) { glFlush(); glflush_hack = 0; } else glflush_hack++; #endif // glDisableClientState( GL_VERTEX_ARRAY ); // glDisableClientState( GL_COLOR_ARRAY ); // glDisableClientState( GL_TEXTURE_COORD_ARRAY ); }
/* ============================== CL_RunFrame ============================== */ const char * CL_RunFrame( const char *in ) { int num_ev; int num_wakeup; int num_run; int num_die; u_list_iter_t iter; cl_ati_t *ati; char tkn[256]; const char *tkn_ptr; // __named_message( "\n" ); TFUNC_ENTER; tkn_ptr = in; // // get current frame time // Parse_GetToken( &tkn_ptr, tkn, 256 ); if ( !tkn[0] ) { __warning( "missing current time in call\n" ); TFUNC_LEAVE; return "fail"; } else { cl_time_begin_frame = cl_time_end_frame; cl_time_end_frame = atoi( tkn ); if ( cl_time_end_frame <= cl_time_begin_frame ) { __warning( "time end < time begin\n" ); TFUNC_LEAVE; return "fail"; } else { cl_time_delta = (cl_time_end_frame-cl_time_begin_frame)/1000.0; } } if ( cl_sv_time >= cl_sv_time_delta ) { // __warning( "client reached end of current server frame\n" ); } #if 0 __named_message( "times: last %d, current %d, delta %d\n", cl_time_last_frame, cl_time_current_frame, cl_time_delta_frame ); #endif // // client frame prepare // cl_time = cl_time_begin_frame; // for hud cl_num_hud = 0; // fixme: proxy killboxes stay only for one client frame, // should there be a timeout CL_ProxyKillBoxMapReset(); // // dispatch all events in the input buffer // for( num_ev = 0;; num_ev++ ) { int remain; // int frm_size; byte_iter_t frm; unique_t id; eventType ev_type; remain = ByteIter_GetSize( bi_in ) - ByteIter_GetOfs( bi_in ); if ( remain == 0 ) break; /*frm_size =*/ UnpackFrame_Begin( bi_in, &frm ); id = ByteIter_Unpacki( &frm ); ev_type = (eventType)ByteIter_Unpacki( &frm ); if ( id == UNIQUE_INVALIDE ) { if ( ev_type >= eventType_client_info_first && ev_type <= eventType_client_info_last ) { if ( ev_type == eventType_client_info_time ) { // server frame time info cl_sv_time_begin_frame = ByteIter_Unpacki( &frm ); cl_sv_time_end_frame = ByteIter_Unpacki( &frm ); cl_sv_time = 0.0; cl_sv_time_delta = (cl_sv_time_end_frame-cl_sv_time_begin_frame)/1000.0; } else { __error( "unknown info event" ); } } else if ( ev_type >= eventType_client_proxy_first && ev_type <= eventType_client_proxy_last ) { if( ev_type == eventType_client_proxy_killbox ) { CL_ProxyKillBoxMapAdd( &frm ); } } else if ( ev_type >= eventType_client_gfx_first && ev_type <= eventType_client_gfx_last ) { if ( ev_type == eventType_client_gfx_create ) { CL_CreateGfxFromEvent( &frm ); } } else { __error( "unknown anonymous event\n" ); } } else { ati = Util_AtiSearchById( id ); if ( ev_type < eventType_client_first || ev_type > eventType_client_last ) { __error( "not a 'client' event" ); } if ( !ati ) { // // if no client object exists for the event // only typeinfo events are allowed to create object // if ( ev_type > eventType_client_typeinfo_first && ev_type < eventType_client_typeinfo_last ) { switch( ev_type ) { case eventType_client_typeinfo_player: { // __named_message( "'typeinfo_player' event\n" ); ati = CL_CreatePlayer( id, &frm ); break; } case eventType_client_typeinfo_view: { // __named_message( "'typeinfo_view' event\n" ); ati = CL_CreateView( id, &frm ); break; } case eventType_client_typeinfo_item: { // __named_message( "'typeinfo_item' event\n" ); ati = CL_CreateItem( id, &frm ); break; } case eventType_client_typeinfo_psys: { // __named_message( "'typeinfo_psys' event\n" ); ati = CL_CreatePsys( id, &frm ); break; } case eventType_client_typeinfo_rocket: { // __named_message( "'typeinfo_rocket' event\n" ); ati = CL_CreateRocket( id, &frm ); break; } default: { __error( "unkown typeinfo\n" ); } } ati->state = clAtiState_run; U_ListInsertAtHead( &cl_ati_list, ati ); Util_AtiRegisterId( ati ); } else { __warning( "ignore event for not existing client object '#%u'\n", id ); } } else { if ( ev_type > eventType_client_typeinfo_first && ev_type < eventType_client_typeinfo_last ) { // __warning( "ignore typeinfo event for existing client object '#%u'\n", id ); } else if ( ev_type > eventType_client_obj_update_first && ev_type < eventType_client_obj_update_last ) { if ( !ati->ftbl->UnpackEvent ) { __error( "object has no unpack ability\n" ); } else { ati->ftbl->UnpackEvent( ati, id, ev_type, &frm ); } } else if ( ev_type > eventType_client_obj_destroy_first && ev_type < eventType_client_obj_destroy_last ) { ati->state = clAtiState_dead; } else { __error( "unknown event for existing client object '#%u'\n", id ); } } } UnpackFrame_End( bi_in, &frm ); } if ( num_ev > 0 ) { // a server frame arrived } num_wakeup = 0; num_run = 0; num_die = 0; // // move wakeup objects to run list // for ( ; ( ati = (cl_ati_t*)U_ListRemoveAtHead( &cl_ati_wakeup_list ) ) ; ) { ati->state = clAtiState_run; U_ListInsertAtHead( &cl_ati_list, ati ); num_wakeup++; } // // run client objects // U_ListIterInit( &iter, &cl_ati_list ); for ( ; ( ati = (cl_ati_t*)U_ListIterNext( &iter ) ) ; ) { if ( ati->ftbl->Run && ( ati->state == clAtiState_none || ati->state == clAtiState_run ) ) { ati->ftbl->Run( ati ); num_run++; } } // // do hud frag // HUD_DrawFragRanking(); // // remove dead objects // U_ListIterInit( &iter, &cl_ati_list ); for ( ; ( ati = (cl_ati_t*)U_ListIterNext( &iter ) ) ; ) { if ( ati->state == clAtiState_dead ) { U_ListIterRemoveGoNext( &iter ); if ( ati->id != UNIQUE_INVALIDE ) { Util_AtiUnregisterRegisterId( ati ); } ati->ftbl->Destroy( ati ); num_die++; } } cl_frame_count++; cl_sv_time += cl_time_delta; // __named_message( "client: %d wakeup, %d run, %d die\n", num_wakeup, num_run, num_die ); TFUNC_LEAVE; return "ok"; }
void R_SetupSFaceLayer( hobj_t *texdef, hobj_t *layer ) { // from texdef vec2d_t shift; vec2d_t scale; fp_t rotate; int projection; g_resource_t *gltex_res; unitex_t *uni; tf2d_stack_t *tf2d_stack; hpair_t *pair; layer_gl_state_t *glstate; layer_t *l; hobj_search_iterator_t iter; hobj_t *job; // from layer vec2d_t scale2; // additional scale color_rgba_t color; // get texdef transform EasyFindVec2d( shift, texdef, "shift" ); EasyFindVec2d( scale, texdef, "scale" ); EasyFindFloat( &rotate, texdef, "rotate" ); EasyFindInt( &projection, texdef, "flags" ); // get layer transform pair = FindHPair( layer, "scale" ); if ( pair ) { HPairCastToVec2d( scale2, pair ); } else { scale2[0] = 1.0; scale2[1] = 1.0; } // get layer ambient color color[0] = 255; color[1] = 255; color[2] = 255; color[3] = 255; pair = FindHPair( layer, "color" ); if ( pair ) { int i; vec3d_t v; HPairCastToVec3d( v, pair ); for ( i = 0; i < 3; i++ ) { if ( v[i] < 0.0 ) v[i] = 0.0; if ( v[i] > 1.0 ) v[i] = 1.0; color[i] = (unsigned char) (v[i]*255.0); } } pair = FindHPair( layer, "alpha" ); if ( pair ) { fp_t a; HPairCastToFloat( &a, pair ); if ( a < 0.0 ) a = 0.0; if ( a > 1.0 ) a = 1.0; color[3] = (unsigned char) (a*255.0); } pair = FindHPair( layer, "gltex_res" ); if ( !pair ) __error( "missing key 'gltex_res'\n" ); gltex_res = G_ResourceSearch( g_rs, pair->value ); if ( !gltex_res ) __error( "can't find gltex resource '%s'\n", pair->value ); uni = UniTex_NewFrom_gltexres( gltex_res ); // layer gl state glstate = NEWTYPE( layer_gl_state_t ); // // blend sfactor // pair = FindHPair( layer, "sfactor" ); if ( !pair ) __error( "missing key 'sfactor'\n" ); if ( !strcmp( pair->value, "GL_ONE" ) ) { glstate->sfactor = GL_ONE; } else if ( !strcmp( pair->value, "GL_ZERO" ) ) { glstate->sfactor = GL_ZERO; } else if ( !strcmp( pair->value, "GL_SRC_COLOR" ) ) { glstate->sfactor = GL_SRC_COLOR; } else if ( !strcmp( pair->value, "GL_SRC_ALPHA" ) ) { glstate->sfactor = GL_SRC_ALPHA; } else { __error( "unknown sfactor '%s'\n", pair->value ); } // // blend dfactor // pair = FindHPair( layer, "dfactor" ); if ( !pair ) __error( "missing key 'dfactor'\n" ); if ( !strcmp( pair->value, "GL_ONE" ) ) { glstate->dfactor = GL_ONE; } else if ( !strcmp( pair->value, "GL_ZERO" ) ) { glstate->dfactor = GL_ZERO; } else if ( !strcmp( pair->value, "GL_ONE_MINUS_SRC_ALPHA" ) ) { glstate->dfactor = GL_ONE_MINUS_SRC_ALPHA; } else { __error( "unknown dfactor '%s'\n", pair->value ); } Layer_BeginInstance( (layerMode)(LayerMode_projection | LayerMode_Texel0N) ); Layer_SetGLstate( glstate ); Layer_SetOrdinal( atoi( layer->name ) ); Layer_SetUniTex( uni ); Layer_SetAmbientColor( color ); if ( (projection&3) == ProjectionType_X ) { Layer_SetProjection( LayerProjection_x ); } else if ( (projection&3) == ProjectionType_Y ) { Layer_SetProjection( LayerProjection_y ); } else if ( (projection&3) == ProjectionType_Z ) { Layer_SetProjection( LayerProjection_z ); } else { __error( "can't get projection plane\n" ); } // // setup layer's transformation stack // tf2d_stack = NEWTYPE( tf2d_stack_t ); TF2D_InitStack( tf2d_stack ); Layer_SetTF2DStack( tf2d_stack ); { tf2d_t *tf2d; tf2d_matrix_t *tf2d_matrix; tf2d = TF2D_CreateMatrix(); tf2d_matrix = TF2D_IsMatrix( tf2d ); TF2D_SetupMatrixByAngle( tf2d_matrix, -rotate ); TF2D_StackPush( tf2d_stack, tf2d ); } { tf2d_t *tf2d; tf2d_scale_t *tf2d_scale; scale[0] *= scale2[0]; scale[1] *= scale2[1]; scale[0] = 1.0/scale[0]; scale[1] = 1.0/scale[1]; tf2d = TF2D_CreateScale(); tf2d_scale = TF2D_IsScale( tf2d ); Vec2dCopy( tf2d_scale->scale, scale ); TF2D_StackPush( tf2d_stack, tf2d ); } { tf2d_t *tf2d; tf2d_shift_t *tf2d_shift; shift[0] = -shift[0]; shift[1] = -shift[1]; tf2d = TF2D_CreateShift(); tf2d_shift = TF2D_IsShift( tf2d ); Vec2dCopy( tf2d_shift->shift, shift ); TF2D_StackPush( tf2d_stack, tf2d ); } l = Layer_EndInstance(); Shape_AddLayer( l ); // // Spawn ShapeCtrlJobs // InitClassSearchIterator( &iter, layer, "job" ); for ( ; ( job = SearchGetNextClass( &iter ) ) ; ) { if ( !strcmp( job->name, "ModulateAlpha" ) ) { R_RegisterShapeCtrlJob( ShapeCtrlJob_Create_ModulateAlpha( job, l ) ); } else if ( !strcmp( job->name, "ModulateColor" ) ) { R_RegisterShapeCtrlJob( ShapeCtrlJob_Create_ModulateColor( job, l ) ); } else if ( !strcmp( job->name, "ShiftTexCoord" ) ) { R_RegisterShapeCtrlJob( ShapeCtrlJob_Create_ShiftTexCoord( job, l ) ); } else if ( !strcmp( job->name, "EnvMap" ) ) { R_RegisterShapeCtrlJob( ShapeCtrlJob_Create_EnvMap( job, l ) ); } else if ( !strcmp( job->name, "DetailMap" ) ) { R_RegisterShapeCtrlJob( ShapeCtrlJob_Create_DetailMap( job, l ) ); } else { __warning( "unknown ShapeCtrlJob '%s', ignore it\n", job->name ); } } }