void view_dim3rtl_effect_mesh_update(void) { int n,count; effect_type *effect; for (n=0;n!=max_effect_list;n++) { effect=server.effect_list.effects[n]; if (effect==NULL) continue; if (!effect->on) continue; if (effect->rtl_mesh_id==-1) continue; count=game_time_get()-effect->start_tick; switch (effect->effecttype) { case ef_particle: view_dim3rtl_effect_mesh_particle_update(effect,count,n); break; case ef_ring: view_dim3rtl_effect_mesh_ring_update(effect,count,n); break; } } }
void effect_dispose(void) { int n,tick; effect_type *effect; tick=game_time_get(); // delete all effects that have timed out for (n=0;n!=max_effect_list;n++) { effect=server.effect_list.effects[n]; if (!effect->on) continue; // has it timed out? if ((tick-effect->start_tick)<effect->life_tick) continue; // is this a chained particle? if (effect->effecttype==ef_particle) { if (particle_chain(effect)) continue; } // dispose effect effect_dispose_single(effect); } }
void liquid_wave_get_high(map_liquid_type *liq,float *wave_y) { float f,fy,f_time,cs; // start with the tide height fy=((float)liq->y)-liquid_tide_get_high(liq); // if no waves, then flat Ys if (!liq->wave.on) { wave_y[0]=wave_y[1]=wave_y[2]=wave_y[3]=fy; return; } // get rate between 0..1 f_time=(float)(game_time_get()%liq->wave.period_msec); f_time=f_time/((float)liq->wave.period_msec); // waves are sin waves cs=cosf((TRIG_PI*2.0f)*f_time); f=((float)liq->wave.high)*cs; wave_y[0]=fy-f; wave_y[1]=wave_y[3]=fy-(f*0.5f); wave_y[2]=fy-(f*0.25f); }
bool particle_chain(effect_type *effect) { particle_effect_data *eff_particle; iface_particle_type *particle; eff_particle=&effect->data.particle; // is there a chain? particle=&iface.particle_list.particles[eff_particle->particle_idx]; if (particle->chain_idx==-1) return(FALSE); // switch to chained particle eff_particle->particle_idx=particle->chain_idx; particle=&iface.particle_list.particles[eff_particle->particle_idx]; effect->start_tick=game_time_get(); effect->life_tick=particle->life_msec; // setup size effect->size=particle_get_effect_size(particle); return(TRUE); }
int js_get_proj_hit_type(proj_type *proj) { map_mesh_poly_type *poly; // check auto hits if (proj->action.hit_tick!=0) { if ((proj->start_tick+proj->action.hit_tick)<=game_time_get()) return(sd_proj_hit_type_auto); } // object or projectile hits if (proj->contact.obj_idx!=-1) return(sd_proj_hit_type_object); if (proj->contact.proj_idx!=-1) return(sd_proj_hit_type_projectile); if (proj->contact.melee) return(sd_proj_hit_type_melee); // map hits // we use wall like flag to determine if // it's a wall hit, and floor/ceiling // hits by proximity to projectile Y if (proj->contact.hit_poly.mesh_idx==-1) return(sd_proj_hit_type_none); poly=&map.mesh.meshes[proj->contact.hit_poly.mesh_idx].polys[proj->contact.hit_poly.poly_idx]; if (poly->box.wall_like) return(sd_proj_hit_type_wall); if (proj->pnt.y>poly->box.mid.y) return(sd_proj_hit_type_ceiling); return(sd_proj_hit_type_floor); }
JSValueRef js_weap_fire_reset_last_fire_func(JSContextRef cx,JSObjectRef func,JSObjectRef j_obj,size_t argc,const JSValueRef argv[],JSValueRef *exception) { weapon_type *weap; if (!script_check_param_count(cx,func,argc,0,exception)) return(script_null_to_value(cx)); weap=weapon_get_attach(j_obj); if (!weap->dual.in_dual) { weap->fire.last_fire_tick=game_time_get(); } else { weap->fire.last_fire_dual_tick=game_time_get(); } return(script_null_to_value(cx)); }
void view_capture_draw(char *path) { int tick; tick=game_time_get(); gl_frame_start(NULL); view_draw(tick); gl_screen_shot(render_info.view_x,render_info.view_y,setup.screen.x_sz,setup.screen.y_sz,TRUE,path); }
float liquid_tide_get_high(map_liquid_type *liq) { float f_time,sn; // get rate between 0..1 f_time=(float)(game_time_get()%liq->tide.rate); f_time=f_time/((float)liq->tide.rate); // waves are sin waves sn=sinf((TRIG_PI*2.0f)*f_time); return(((float)liq->tide.high)*sn); }
void draw_weapon_hand_setup(obj_type *obj,weapon_type *weap) { int tick; model_draw *draw; model_type *mdl; // weapons hidden or zoom on? if (obj->hide_all_weapons) return; if ((weap->zoom.on) && (weap->zoom.mode!=zoom_mode_off) && (obj->zoom_draw.on) && (!weap->zoom.show_weapon)) return; // weapon model draw draw=&weap->draw; if ((draw->model_idx==-1) || (!draw->on)) return; mdl=server.model_list.models[draw->model_idx]; // regular weapon model tick=game_time_get(); model_draw_setup_clear(mdl,&draw->setup); model_draw_setup_weapon(obj,weap,FALSE,FALSE); model_calc_animation(draw,tick); model_calc_draw_bones(draw); render_model_setup(draw,tick); render_model_build_vertex_lists(draw,TRUE); // dual wielded weapons if ((weap->dual.on) && (weap->dual.active)) { draw=&weap->draw_dual; if ((draw->model_idx!=-1) && (draw->on)) { mdl=server.model_list.models[draw->model_idx]; model_draw_setup_clear(mdl,&draw->setup); model_draw_setup_weapon(obj,weap,FALSE,TRUE); model_calc_animation(draw,tick); model_calc_draw_bones(draw); render_model_setup(draw,tick); render_model_build_vertex_lists(draw,TRUE); } } }
float liquid_tide_get_uv_factor(map_liquid_type *liq) { float f_time,sn,shift; // get rate between 0..1 f_time=(float)(game_time_get()%liq->tide.rate); f_time=f_time/((float)liq->tide.rate); // waves are sin waves sn=sinf((TRIG_PI*2.0f)*f_time); shift=liq->tide.uv_shift*0.5f; return(shift+(shift*sn)); }
void game_file_create_name(int tick,char *file_name) { int sec; char elapse_str[32],time_str[32]; struct tm *tm; time_t curtime; curtime=time(NULL); tm=localtime(&curtime); sprintf(time_str,"%.4d%.2d%.2d%.2d%.2d",(tm->tm_year+1900),(tm->tm_mon+1),tm->tm_mday,tm->tm_hour,tm->tm_min); sec=(game_time_get()-map.start_game_tick)/1000; if (sec>(99*60)) sec=99*60; sprintf(elapse_str,"%.2d%.2d",(sec/60),(sec%60)); sprintf(file_name,"%s_%s_%s",time_str,elapse_str,map.info.name); }
int effect_spawn(int effecttype,d3pnt *pt,int life_tick) { int n,idx; effect_type *effect; // can't spawn 0 time effects if (life_tick<=0) { console_add_error("Can't spawn effects with no life time"); return(-1); } // any more effect spots? // this is a silent error, as it's not fatal // and not script-based idx=-1; for (n=0;n!=max_effect_list;n++) { effect=server.effect_list.effects[n]; if (!effect->on) { idx=n; break; } } if (idx==-1) return(-1); // create effect effect=server.effect_list.effects[idx]; effect->on=TRUE; effect->effecttype=effecttype; memmove(&effect->pnt,pt,sizeof(d3pnt)); effect->mesh_idx=map_mesh_find(&map,pt); effect->start_tick=game_time_get(); effect->life_tick=life_tick; effect->rtl_mesh_id=-1; return(idx); }
void zoom_setup(obj_type *obj,weapon_type *weap) { int tx,ty,old_x,old_y; obj_zoom_draw *zoom_draw; zoom_draw=&obj->zoom_draw; // get last position is zoom was on old_x=old_y=-1; if (zoom_draw->on) { old_x=zoom_draw->x; old_y=zoom_draw->y; } // zoom on? zoom_draw->on=FALSE; if (obj->hide_all_weapons) return; if ((!weap->zoom.on) || (weap->zoom.mode==zoom_mode_off)) return; // iron sites effect masking if (game_time_get()<(zoom_draw->start_tick+weap->zoom.tick)) return; // get the zoom place if (!crosshair_get_location(obj,weap,&tx,&ty,NULL,NULL)) return; zoom_draw->on=TRUE; // smooth out if (old_x!=-1) { tx=(tx+old_x)>>1; ty=(ty+old_y)>>1; }
void view_draw_dim3rtl_scene_build(void) { int n,tick; obj_type *obj; proj_type *proj; map_light_type *lit; map_particle_type *prt; // build the scene // we don't have to do as much as opengl // so just setup the animations tick=game_time_get(); view_setup_objects_rtl(tick); view_setup_projectiles_rtl(tick); // update the sky cube sky_update(); // no halos yet halo_draw_clear(); // create the model vertex/etc // lists for updating rtl and // add any halos for (n=0; n!=max_obj_list; n++) { obj=server.obj_list.objs[n]; if (obj==NULL) continue; if (obj->hidden) continue; render_model_build_vertex_lists(&obj->draw,TRUE); view_add_model_halo(&obj->draw,obj->idx); } for (n=0; n!=max_proj_list; n++) { proj=server.proj_list.projs[n]; if (!proj->on) continue; render_model_build_vertex_lists(&proj->draw,FALSE); view_add_model_halo(&proj->draw,-1); } // map and particle halos lit=map.lights; for (n=0; n!=map.nlight; n++) { halo_draw_add(&lit->pnt,-1,lit->setting.halo_idx); lit++; } prt=map.particles; for (n=0; n!=map.nparticle; n++) { halo_draw_add(&prt->pnt,-1,prt->light_setting.halo_idx); prt++; } }
bool liquid_render_liquid_create_vertex(map_liquid_type *liq,float uv_shift,bool is_overlay) { int k,div,div_count,lft,rgt,top,bot, top_add,lft_add; float fy,wave_y[4],f_tick,f_stamp_size, gx,gy,gx2,gy2,gx_add,gy_add, lmap_gx,lmap_gy,lmap_gx2,lmap_gy2,lmap_gx_add,lmap_gy_add; float *cf; unsigned char *vertex_ptr,*vp; d3vct normal; // setup vbo view_bind_mesh_liquid_vertex_object(&liq->vbo); vertex_ptr=view_map_mesh_liquid_vertex_object(&liq->vbo); if (vertex_ptr==NULL) { view_unbind_mesh_liquid_vertex_object(); return(FALSE); } // uv shift tick f_tick=((float)game_time_get())*0.001f; // liquid texture uvs if (is_overlay) { gx_add=f_tick*liq->overlay.shift.x; k=(int)gx_add; gx_add=gx_add-(float)k; gy_add=f_tick*liq->overlay.shift.y; k=(int)gy_add; gy_add=gy_add-(float)k; f_stamp_size=1.0f/((float)liq->overlay.stamp_size); gx=((float)liq->lft)*f_stamp_size; gx2=((float)liq->rgt)*f_stamp_size; k=(int)gx; gx-=((float)k); gx2-=((float)k); gy=((float)liq->top)*f_stamp_size; gy2=((float)liq->bot)*f_stamp_size; k=(int)gx; gy-=((float)k); gy2-=((float)k); gx+=gx_add; gy+=gy_add; gx2+=gx_add; gy2+=gy_add; } else { gx_add=f_tick*liq->shift.x; k=(int)gx_add; gx_add=gx_add-(float)k; gy_add=f_tick*liq->shift.y; k=(int)gy_add; gy_add=gy_add-(float)k; gx=liq->main_uv.offset.x+gx_add; gy=liq->main_uv.offset.y+gy_add; gx2=gx+liq->main_uv.size.x; gy2=gy+liq->main_uv.size.y; } // uv factors gx+=uv_shift; gy+=uv_shift; gx2-=uv_shift; gy2-=uv_shift; // build the tide and wave Y liquid_wave_get_high(liq,wave_y); // get div count and setup // the division calculations lft=liq->lft; rgt=liq->rgt; top=liq->top; bot=liq->bot; lmap_gx=liq->lmap_uv.offset.x; lmap_gx2=liq->lmap_uv.offset.x+liq->lmap_uv.size.x; lmap_gy=liq->lmap_uv.offset.y; lmap_gy2=liq->lmap_uv.offset.y+liq->lmap_uv.size.y; div_count=liquid_wave_get_divisions(liq); lft_add=rgt-lft; gx_add=gx2-gx; lmap_gx_add=lmap_gx2-lmap_gx; top_add=bot-top; gy_add=gy2-gy; lmap_gy_add=lmap_gy2-lmap_gy; if (liq->wave.on) { if (liq->wave.dir_north_south) { top_add=liq->wave.length; gy_add=(gy2-gy)/((float)div_count); lmap_gy_add=(lmap_gy2-lmap_gy)/((float)div_count); } else { lft_add=liq->wave.length; gx_add=(gx2-gx)/((float)div_count); lmap_gx_add=(lmap_gx2-lmap_gx)/((float)div_count); } } // draw the divisions vp=vertex_ptr; for (div=0;div<=div_count;div++) { fy=wave_y[div&0x3]; // north-south (z) waves if (liq->wave.dir_north_south) { // normal liquid_wave_get_normal_z(liq,div,wave_y,top_add,&normal); // left-top cf=(float*)vp; *cf++=(float)lft; *cf++=fy; *cf++=(float)top; *cf++=gx; *cf++=gy; *cf++=lmap_gx; *cf++=lmap_gy; *cf++=1.0f; *cf++=0.0f; *cf++=0.0f; *cf++=normal.x; *cf++=normal.y; *cf++=normal.z; vp+=liq->vbo.vertex_stride; // right-top cf=(float*)vp; *cf++=(float)rgt; *cf++=fy; *cf++=(float)top; *cf++=gx2; *cf++=gy; *cf++=lmap_gx2; *cf++=lmap_gy; *cf++=1.0f; *cf++=0.0f; *cf++=0.0f; *cf++=normal.x; *cf++=normal.y; *cf++=normal.z; vp+=liq->vbo.vertex_stride; // div change top+=top_add; if (top>liq->bot) top=liq->bot; gy+=gy_add; if (gy>gy2) gy=gy2; lmap_gy+=lmap_gy_add; if (lmap_gy>lmap_gy2) lmap_gy=lmap_gy2; } // east-west (x) waves else { // normal liquid_wave_get_normal_x(liq,div,wave_y,lft_add,&normal); // left-top cf=(float*)vp; *cf++=(float)lft; *cf++=fy; *cf++=(float)top; *cf++=gx; *cf++=gy; *cf++=lmap_gx; *cf++=lmap_gy; *cf++=1.0f; *cf++=0.0f; *cf++=0.0f; *cf++=normal.x; *cf++=normal.y; *cf++=normal.z; vp+=liq->vbo.vertex_stride; // left-bottom cf=(float*)vp; *cf++=(float)lft; *cf++=fy; *cf++=(float)bot; *cf++=gx; *cf++=gy2; *cf++=lmap_gx; *cf++=lmap_gy2; *cf++=1.0f; *cf++=0.0f; *cf++=0.0f; *cf++=normal.x; *cf++=normal.y; *cf++=normal.z; vp+=liq->vbo.vertex_stride; // div change lft+=lft_add; if (lft>liq->rgt) lft=liq->rgt; gx+=gx_add; if (gx>gx2) gx=gx2; lmap_gx+=lmap_gx_add; if (lmap_gx>lmap_gx2) lmap_gx=lmap_gx2; } } view_unmap_mesh_liquid_vertex_object(); view_unbind_mesh_liquid_vertex_object(); // indexes are pre-created on startup return(TRUE); }
void fog_draw_textured(void) { int n,k,tick,count,outer_radius,inner_radius, radius_add,radius,frame,mem_sz; unsigned long gl_id; float r_ang,r_shift,r_ang_2,r_add,fx,fz,fx_1,fx_2,fz_1,fz_2,f_ty,f_by, f_radius,gx,gx2; float *vp; d3col col; texture_type *texture; // textured fog on? if ((!map.fog.on) || (map.fog.use_solid_color)) return; // if this is first time, setup VBO if (!fog_vbo_created) { fog_vbo_created=TRUE; mem_sz=(((16*6)*map.fog.count)*(3+2))*sizeof(float); view_create_fog_vertex_object(mem_sz); } // drawing layers count=map.fog.count; outer_radius=map.fog.outer_radius; inner_radius=map.fog.inner_radius; radius_add=(inner_radius-outer_radius)/count; // construct VBO view_bind_fog_vertex_object(); vp=(float*)view_map_fog_vertex_object(); if (vp==NULL) { view_unbind_fog_vertex_object(); return; } // get drawing setup tick=game_time_get(); r_add=ANG_to_RAD*(360.0f/16.0f); r_shift=(ANG_to_RAD*360.0f)/((float)count); radius=outer_radius; fx=(float)view.render->camera.pnt.x; fz=(float)view.render->camera.pnt.z; f_ty=(float)(view.render->camera.pnt.y-map.fog.high); f_by=(float)(view.render->camera.pnt.y+map.fog.drop); // create the fog triangle vertexes for (n=0;n!=count;n++) { gx=0.0f; r_ang=r_shift*((float)n); f_radius=(float)radius; for (k=0;k!=16;k++) { r_ang_2=r_ang+r_add; fx_1=(-sinf(r_ang)*f_radius)+fx; fx_2=(-sinf(r_ang_2)*f_radius)+fx; fz_1=-(cosf(r_ang)*f_radius)+fz; fz_2=-(cosf(r_ang_2)*f_radius)+fz; gx2=gx+0.5f; // triangle 1 *vp++=fx_1; *vp++=f_ty; *vp++=fz_1; *vp++=gx; *vp++=0.0f; *vp++=fx_2; *vp++=f_ty; *vp++=fz_2; *vp++=gx2; *vp++=0.0f; *vp++=fx_1; *vp++=f_by; *vp++=fz_1; *vp++=gx; *vp++=1.0f; // triangle 2 *vp++=fx_2; *vp++=f_ty; *vp++=fz_2; *vp++=gx2; *vp++=0.0f; *vp++=fx_2; *vp++=f_by; *vp++=fz_2; *vp++=gx2; *vp++=1.0f; *vp++=fx_1; *vp++=f_by; *vp++=fz_1; *vp++=gx; *vp++=1.0f; r_ang=r_ang_2; gx+=0.5f; if (gx==1.0f) gx=0.0f; } radius+=radius_add; } view_unmap_fog_vertex_object(); // setup drawing glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_DEPTH_TEST); glDepthMask(GL_FALSE); col.r=col.g=col.b=1.0f; texture=&map.textures[map.fog.texture_idx]; frame=texture->animate.current_frame&max_texture_frame_mask; gl_id=texture->frames[frame].bitmap.gl_id; // draw the fog gl_shader_draw_execute_simple_bitmap_set_texture(gl_id); gl_shader_draw_execute_simple_bitmap_start(3,0,(3*sizeof(float)),((3+2)*sizeof(float)),&col,map.fog.alpha); glDrawArrays(GL_TRIANGLES,0,((16*6)*count)); gl_shader_draw_execute_simple_bitmap_end(); glDepthMask(GL_TRUE); // unbind the vbo view_unbind_fog_vertex_object(); }
void debug_dump(void) { int i,idx,cnt,mem_sz; obj_type *obj; effect_type *effect; proj_type *proj; weapon_type *weap; proj_setup_type *proj_setup; model_type *mdl; script_type *script; timer_type *timer; SDL_version *sdl_ver; console_add_system("Debugging info dumped to stdout"); fprintf(stdout,"\n\n"); fprintf(stdout,"#########################################################################\n"); fprintf(stdout,"Dump: dim3 Debugging Info\n"); fprintf(stdout,"Engine v%s\n",dim3_version); fprintf(stdout,"(c) 2000-2007 Klink! Software\n"); fprintf(stdout,"#########################################################################\n\n"); // game info fprintf(stdout,"**************************************\n"); fprintf(stdout,"Game\n"); fprintf(stdout,"**************************************\n\n"); fprintf(stdout,"Project: %s\n",net_setup.host.proj_name); fprintf(stdout,"Tick: %d\n",game_time_get()); debug_return(); // system info fprintf(stdout,"**************************************\n"); fprintf(stdout,"System\n"); fprintf(stdout,"**************************************\n\n"); fprintf(stdout,"Arch Type: %s\n",arch_type); #ifdef D3_OS_MAC fprintf(stdout,"OS Version: %d.%d.%d\n",os_vers_major,os_vers_minor_1,os_vers_minor_2); #endif sdl_ver=(SDL_version*)SDL_Linked_Version(); fprintf(stdout,"SDL Version: %d.%d.%d\n",sdl_ver->major,sdl_ver->minor,sdl_ver->patch); fprintf(stdout,"JavaScript Version: %.2f\n",((float)JS_VERSION/100.0f)); fprintf(stdout,"PNG Version: %s\n",PNG_LIBPNG_VER_STRING); debug_return(); // video info fprintf(stdout,"**************************************\n"); fprintf(stdout,"Video\n"); fprintf(stdout,"**************************************\n\n"); fprintf(stdout,"Engine: %s\n",render_info.name); fprintf(stdout,"Screen: %d,%d at %d\n",render_info.monitor_x_sz,render_info.monitor_y_sz,render_info.monitor_refresh_rate); fprintf(stdout,"Max Texture Units: %d\n",render_info.texture_unit_count); fprintf(stdout,"Max Texture Size: %d\n",render_info.texture_max_size); if (!gl_check_frame_buffer_ok()) fprintf(stdout,"Shadow support disabled; Unsupported on this video card.\n"); if (!gl_check_fsaa_ok()) fprintf(stdout,"FSAA support disabled; Unsupported on this video card.\n"); if (!gl_check_texture_compress_ok()) fprintf(stdout,"Compression disabled; Unsupported on this video card.\n"); if (!gl_check_point_sprite_ok()) fprintf(stdout,"Point sprite support disabled; Unsupported on this video card.\n"); if (!gl_check_shader_ok()) fprintf(stdout,"GLSL support disabled; Unsupported on this video card.\n"); fprintf(stdout,"Extensions:\n%s\n",render_info.ext_string); #ifdef D3_OS_WINDOWS fprintf(stdout,"WGL Extensions:\n%s\n",wglGetExtensionsStringARB(wglGetCurrentDC())); #endif debug_return(); // map info fprintf(stdout,"**************************************\n"); fprintf(stdout,"Map\n"); fprintf(stdout,"**************************************\n\n"); fprintf(stdout,"Map: %s\n",map.info.name); fprintf(stdout,"Author: %s\n",map.info.author); fprintf(stdout,"Mesh Count: %d\n",map.mesh.nmesh); fprintf(stdout,"Liquid Count: %d\n",map.liquid.nliquid); fprintf(stdout,"Spot Count: %d\n",map.nspot); fprintf(stdout,"Scenery Count: %d\n",map.nscenery); fprintf(stdout,"Node Count: %d\n",map.nnode); debug_return(); // objects debug_header("Objects",server.count.obj,(sizeof(obj_type)*server.count.obj)); debug_space("Name",25); debug_space("Type",15); debug_space("Script",25); debug_space("Binding",10); debug_return(); debug_space("------------------------",25); debug_space("------------------------",15); debug_space("------------------------",25); debug_space("---------",10); debug_return(); obj=server.objs; for ((i=0);(i!=server.count.obj);i++) { debug_space(obj->name,25); debug_space(obj->type,15); if (!obj->scenery.on) { idx=scripts_find_uid(obj->attach.script_uid); debug_space(js.scripts[idx].name,25); } else { debug_space("*",25); } debug_space(bind_type_str[obj->bind],10); debug_return(); obj++; } debug_return(); // weapons debug_header("Weapons",server.count.weapon,(sizeof(weapon_type)*server.count.weapon)); debug_space("Name",20); debug_space("Object",20); debug_return(); debug_space("-------------------",20); debug_space("-------------------",20); debug_return(); weap=server.weapons; for ((i=0);(i!=server.count.weapon);i++) { obj=object_find_uid(weap->obj_uid); debug_space(weap->name,20); debug_space(obj->name,20); debug_return(); weap++; } debug_return(); // projectile setups debug_header("Projectile Setups",server.count.proj_setup,(sizeof(proj_setup_type)*server.count.proj_setup)); debug_space("Name",20); debug_space("Object",20); debug_space("Weapon",20); debug_return(); debug_space("-------------------",20); debug_space("-------------------",20); debug_space("-------------------",20); debug_return(); proj_setup=server.proj_setups; for ((i=0);(i!=server.count.proj_setup);i++) { obj=object_find_uid(proj_setup->obj_uid); weap=weapon_find_uid(proj_setup->weap_uid); debug_space(proj_setup->name,20); debug_space(obj->name,20); debug_space(weap->name,20); debug_return(); proj_setup++; } debug_return(); // models mem_sz=sizeof(model_type)*server.count.model; mdl=server.models; for (i=0;i!=server.count.model;i++) { mem_sz+=model_memory_size(mdl); mdl++; } debug_header("Models",server.count.model,mem_sz); debug_space("Name",32); debug_space("Vertexes",10); debug_space("Trigs",10); debug_space("Ref Count",10); debug_return(); debug_space("------------------------------",32); debug_space("---------",10); debug_space("---------",10); debug_space("---------",10); debug_return(); mdl=server.models; for (i=0;i!=server.count.model;i++) { debug_space(mdl->name,32); debug_int_space(mdl->meshes[0].nvertex,10); debug_int_space(mdl->meshes[0].ntrig,10); debug_int_space(mdl->reference_count,10); debug_return(); mdl++; } debug_return(); // projectiles debug_header("Projectiles",server.count.proj,(sizeof(proj_type)*max_projectile)); debug_space("Name",20); debug_space("Object",20); debug_space("Weapon",20); debug_return(); debug_space("-------------------",20); debug_space("-------------------",20); debug_space("-------------------",20); debug_return(); proj=server.projs; for ((i=0);(i!=server.count.proj);i++) { obj=object_find_uid(proj->obj_uid); weap=weapon_find_uid(proj->weap_uid); proj_setup=proj_setups_find_uid(proj->proj_setup_uid); debug_space(proj_setup->name,20); debug_space(obj->name,20); debug_space(weap->name,20); debug_return(); proj++; } debug_return(); // effects debug_header("Effects",server.count.effect,(sizeof(effect_type)*max_effect)); debug_space("Type",10); debug_space("Life Tick",10); debug_return(); debug_space("---------",10); debug_space("---------",10); debug_return(); effect=server.effects; for ((i=0);(i!=server.count.effect);i++) { debug_space(effect_type_str[effect->effecttype],10); debug_int_space(effect->life_tick,10); debug_return(); effect++; } debug_return(); // scripts script=js.scripts; cnt=0; for ((i=0);(i!=max_scripts);i++) { if (script->used) cnt++; script++; } debug_header("Scripts",cnt,-1); debug_space("Name",32); debug_return(); debug_space("-------------------------------",32); debug_return(); script=js.scripts; for ((i=0);(i!=max_scripts);i++) { if (script->used) { debug_space(script->name,32); debug_return(); } script++; } debug_return(); // timers debug_header("Timers",js.count.timer,-1); debug_space("Script",32); debug_space("Count",10); debug_space("Type",10); debug_return(); debug_space("-------------------------------",32); debug_space("---------",10); debug_space("---------",10); debug_return(); timer=js.timers; for ((i=0);(i!=js.count.timer);i++) { script=&js.scripts[scripts_find_uid(timer->attach.script_uid)]; debug_space(script->name,32); debug_int_space(timer->count,10); debug_space((timer->mode==timer_mode_repeat)?"Timer":"Wait",10); debug_return(); timer++; } debug_return(); fflush(stdout); }
void view_dim3rtl_map_liquid_create_draw_data(map_liquid_type *liq) { int k,div,div_count, lft,rgt,top,bot, top_add,lft_add; float fy,f_tick,wave_y[4], gx,gy,gx2,gy2,gx_add,gy_add; float *vp,*vu,*vn,*vt; d3vct normal; // setup waves div_count=liquid_wave_get_divisions(liq); liquid_wave_get_high(liq,wave_y); // map pointers rtlSceneMeshMapVertexPointer(view_rtl_draw_scene_id,liq->rtl_mesh_id,(void**)&vp); rtlSceneMeshMapUVPointer(view_rtl_draw_scene_id,liq->rtl_mesh_id,(void**)&vu); rtlSceneMeshMapNormalPointer(view_rtl_draw_scene_id,liq->rtl_mesh_id,(void**)&vn); rtlSceneMeshMapTangentPointer(view_rtl_draw_scene_id,liq->rtl_mesh_id,(void**)&vt); // get current UVs f_tick=((float)game_time_get())*0.001f; gx_add=f_tick*liq->shift.x; k=(int)gx_add; gx_add=gx_add-(float)k; gy_add=f_tick*liq->shift.y; k=(int)gy_add; gy_add=gy_add-(float)k; gx=liq->main_uv.offset.x+gx_add; gy=liq->main_uv.offset.y+gy_add; gx2=gx+liq->main_uv.size.x; gy2=gy+liq->main_uv.size.y; // get div count and setup // the division calculations lft=liq->lft; rgt=liq->rgt; top=liq->top; bot=liq->bot; lft_add=rgt-lft; gx_add=gx2-gx; top_add=bot-top; gy_add=gy2-gy; if (liq->wave.on) { if (liq->wave.dir_north_south) { top_add=liq->wave.length; gy_add=(gy2-gy)/((float)div_count); } else { lft_add=liq->wave.length; gx_add=(gx2-gx)/((float)div_count); } } // create the divisions for (div=0;div<=div_count;div++) { fy=wave_y[div&0x3]; // north-south (z) waves if (liq->wave.dir_north_south) { // the normal liquid_wave_get_normal_z(liq,div,wave_y,top_add,&normal); // left-top *vp++=(float)lft; *vp++=fy; *vp++=(float)top; *vu++=gx; *vu++=gy; *vn++=normal.x; *vn++=normal.y; *vn++=normal.z; *vt++=1.0f; *vt++=0.0f; *vt++=0.0f; // right-top *vp++=(float)rgt; *vp++=fy; *vp++=(float)top; *vu++=gx2; *vu++=gy; *vn++=normal.x; *vn++=normal.y; *vn++=normal.z; *vt++=1.0f; *vt++=0.0f; *vt++=0.0f; // division change top+=top_add; if (top>liq->bot) top=liq->bot; gy+=gy_add; if (gy>gy2) gy=gy2; } // east-west (x) waves else { // the normal liquid_wave_get_normal_x(liq,div,wave_y,lft_add,&normal); // left-top *vp++=(float)lft; *vp++=fy; *vp++=(float)top; *vu++=gx; *vu++=gy; *vn++=normal.x; *vn++=normal.y; *vn++=normal.z; *vt++=1.0f; *vt++=0.0f; *vt++=0.0f; // left-bottom *vp++=(float)lft; *vp++=fy; *vp++=(float)bot; *vu++=gx; *vu++=gy2; *vn++=normal.x; *vn++=normal.y; *vn++=normal.z; *vt++=1.0f; *vt++=0.0f; *vt++=0.0f; // division changes lft+=lft_add; if (lft>liq->rgt) lft=liq->rgt; gx+=gx_add; if (gx>gx2) gx=gx2; } } // unmap the pointers rtlSceneMeshUnMapVertexPointer(view_rtl_draw_scene_id,liq->rtl_mesh_id); rtlSceneMeshUnMapUVPointer(view_rtl_draw_scene_id,liq->rtl_mesh_id); rtlSceneMeshUnMapNormalPointer(view_rtl_draw_scene_id,liq->rtl_mesh_id); rtlSceneMeshUnMapTangentPointer(view_rtl_draw_scene_id,liq->rtl_mesh_id); }
bool view_initialize(char *err_str) { int rate; // clear view structure memset(&view,0x0,sizeof(view_type)); // allocate memory if (!view_memory_allocate()) { view_memory_release(); strcpy(err_str,"Out of Memory"); return(FALSE); } // start SDL if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_JOYSTICK|SDL_INIT_NOPARACHUTE)==-1) { view_memory_release(); sprintf(err_str,"SDL: Could not init (Error: %s)\n",SDL_GetError()); return(FALSE); } // create screen sizes view_create_screen_size_list(); // gl initialize if (!view_initialize_display(err_str)) return(FALSE); // sound initialize if (!al_initialize(err_str)) { view_shutdown_display(); view_memory_release(); SDL_Quit(); return(FALSE); } al_set_volume(setup.sound_volume); al_music_set_volume(setup.music_volume); al_music_set_state(setup.music_on); // read in the sounds read_settings_sound(); // connect the input read_settings_action(); input_initialize(gl_in_window_mode()); setup_to_input(); // draw timing view.time.input_tick=game_time_get(); view.time.draw_tick=game_time_get(); rate=render_info.monitor_refresh_rate; if (!setup.lock_fps_refresh) rate=max_fps; if (rate>max_fps) rate=max_fps; view.time.draw_time=1000/rate; return(TRUE); }
int net_host_join_request(net_address_type *addr,network_request_join *request_join) { int net_uid, tint_color_idx; char *c; obj_type *obj; network_reply_join reply_join; network_request_remote_add add; // check if join is OK net_uid=-1; reply_join.deny_reason[0]=0x0; // create remote UID when // adding this new remote player tint_color_idx=0; if (net_host_join_request_ok(request_join,&reply_join)) { tint_color_idx=htons((short)request_join->tint_color_idx); net_uid=net_host_player_add(addr,FALSE,request_join->name,request_join->draw_name,tint_color_idx); } // construct the reply reply_join.join_net_uid=htons((short)net_uid); reply_join.team_idx=htons((short)net_team_none); reply_join.map_tick=htonl(game_time_get()-map.start_game_tick); // build a remote add request for other // clients in the game // so we can add a remote, we start with a fake // team (none), after we add, we can call the game // rules and reset it add.add_net_uid=htons((short)net_uid); add.type=htons((short)object_type_remote_player); strncpy(add.name,request_join->name,name_str_len); strncpy(add.script_name,request_join->script_name,name_str_len); c=strrchr(add.script_name,'.'); // remove .js if (c!=0x0) *c=0x0; strncpy(add.draw_name,request_join->draw_name,name_str_len); add.team_idx=htons((short)net_team_none); add.tint_color_idx=htons((short)tint_color_idx); add.score=0; add.name[name_str_len-1]=0x0; add.script_name[name_str_len-1]=0x0; add.draw_name[name_str_len-1]=0x0; // create the remote object if (!remote_add(&add)) { net_uid=-1; } // run team rule if (net_uid!=-1) { obj=object_find_remote_net_uid(net_uid); object_multiplayer_setup(obj); // reset team in reply and remote add reply_join.team_idx=htons((short)obj->team_idx); add.team_idx=htons((short)obj->team_idx); } // send reply back to client if (!net_sendto_msg(host_socket,addr,net_action_reply_join,(unsigned char*)&reply_join,sizeof(network_reply_join))) { if (net_uid!=-1) net_host_player_remove_by_uid(net_uid); return(FALSE); } // if no player uid, then player was rejected if (net_uid==-1) return(FALSE); // send all other players on host the new player for remote add net_host_player_send_message_to_clients_all(addr,net_action_request_remote_add,(unsigned char*)&add,sizeof(network_request_remote_add)); return(net_uid); }
void decal_render_mark(int stencil_idx,decal_type *decal) { int k,tick,fade_out_start_tick; float alpha,g_size,gx,gy; float cf[3]; float *vp; d3col col; iface_mark_type *mark; // get the alpha mark=&iface.mark_list.marks[decal->mark_idx]; alpha=decal->alpha; tick=game_time_get()-decal->start_tick; if (tick<mark->fade_in_msec) { alpha=(alpha*(float)tick)/(float)mark->fade_in_msec; } else { fade_out_start_tick=mark->fade_in_msec+mark->life_msec; if (tick>=fade_out_start_tick) { k=tick-fade_out_start_tick; alpha=(alpha*(float)(mark->fade_out_msec-k))/(float)mark->fade_out_msec; } } // blending if (mark->blend_add) { glBlendFunc(GL_SRC_ALPHA,GL_ONE); } else { glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); } // get the decal image effect_image_animate_get_uv(tick,0,&mark->animate,&gx,&gy,&g_size); // get lighting if (mark->hilite) { col.r=col.g=col.b=1.0f; } else { gl_lights_calc_color((float)decal->x[0],(float)decal->y[0],(float)decal->z[0],cf); col.r=cf[0]; col.g=cf[1]; col.b=cf[2]; } // setup vertex ptr view_bind_utility_vertex_object(); vp=(float*)view_map_utility_vertex_object(); *vp++=(float)decal->x[0]; *vp++=(float)decal->y[0]; *vp++=(float)decal->z[0]; *vp++=gx; *vp++=gy; *vp++=(float)decal->x[3]; *vp++=(float)decal->y[3]; *vp++=(float)decal->z[3]; *vp++=gx; *vp++=gy+g_size; *vp++=(float)decal->x[1]; *vp++=(float)decal->y[1]; *vp++=(float)decal->z[1]; *vp++=gx+g_size; *vp++=gy; *vp++=(float)decal->x[2]; *vp++=(float)decal->y[2]; *vp++=(float)decal->z[2]; *vp++=gx+g_size; *vp++=gy+g_size; view_unmap_utility_vertex_object(); // draw the polygon gl_shader_draw_execute_simple_bitmap_set_texture(view_images_get_gl_id(mark->image_idx)); gl_shader_draw_execute_simple_bitmap_start(3,0,(3*sizeof(float)),((3+2)*sizeof(float)),&col,alpha); glStencilFunc(GL_EQUAL,stencil_idx,0xFF); glDrawArrays(GL_TRIANGLE_STRIP,0,4); gl_shader_draw_execute_simple_bitmap_end(); view_unbind_utility_vertex_object(); }
bool game_file_save(char *err_str) { int tick; char path[1024],file_name[256]; bool ok; file_save_header head; progress_initialize("Saving"); progress_draw(5); // get saved data file names tick=game_time_get(); game_file_create_name(tick,file_name); // save screen file_paths_documents(&setup.file_path_setup,path,"Saved Games",file_name,"png"); view_capture_draw(path); // start chunks game_file_sz=0; game_file_data=malloc(32); // header head.tick=tick; strcpy(head.version,dim3_version); strcpy(head.map_name,map.info.name); game_file_add_chunk(&head,1,sizeof(file_save_header)); // send scripts save event // to backup globals progress_draw(10); script_state_save(); // view & server objects progress_draw(20); game_file_add_chunk(&view.time,1,sizeof(view_time_type)); game_file_add_chunk(&view.fps,1,sizeof(view_fps_type)); game_file_add_chunk(&camera,1,sizeof(camera_type)); game_file_add_chunk(&server.time,1,sizeof(server_time_type)); game_file_add_chunk(&server.player_obj_uid,1,sizeof(int)); game_file_add_chunk(&server.skill,1,sizeof(int)); game_file_add_chunk(&server.uid,1,sizeof(server_uid_type)); game_file_add_chunk(&server.count,1,sizeof(server_count_type)); progress_draw(30); game_file_add_chunk(server.objs,server.count.obj,sizeof(obj_type)); game_file_add_chunk(server.weapons,server.count.weapon,sizeof(weapon_type)); game_file_add_chunk(server.proj_setups,server.count.proj_setup,sizeof(proj_setup_type)); progress_draw(40); game_file_add_chunk(server.projs,server.count.proj,sizeof(proj_type)); game_file_add_chunk(server.effects,server.count.effect,sizeof(effect_type)); game_file_add_chunk(server.decals,server.count.decal,sizeof(decal_type)); progress_draw(50); game_file_add_chunk(hud.bitmaps,hud.count.bitmap,sizeof(hud_bitmap_type)); game_file_add_chunk(hud.texts,hud.count.text,sizeof(hud_text_type)); game_file_add_chunk(hud.bars,hud.count.bar,sizeof(hud_bar_type)); game_file_add_chunk(&hud.radar,1,sizeof(hud_radar_type)); // map changes progress_draw(60); game_file_add_chunk(&map.ambient,1,sizeof(map_ambient_type)); game_file_add_chunk(&map.rain,1,sizeof(map_rain_type)); game_file_add_chunk(&map.background,1,sizeof(map_background_type)); game_file_add_chunk(&map.sky,1,sizeof(map_sky_type)); game_file_add_chunk(&map.fog,1,sizeof(map_fog_type)); progress_draw(70); game_file_add_chunk(map.groups,1,sizeof(group_type)*map.ngroup); game_file_add_chunk(map.movements,1,sizeof(movement_type)*map.nmovement); // script objects progress_draw(80); game_file_add_chunk(&js.script_current_uid,1,sizeof(int)); game_file_add_chunk(&js.count,1,sizeof(script_count_type)); game_file_add_chunk(&js.time,1,sizeof(script_time_type)); game_file_add_chunk(js.timers,js.count.timer,sizeof(timer_type)); game_file_add_chunk(js.globals,js.count.global,sizeof(global_type)); // compress and save progress_draw(90); file_paths_documents(&setup.file_path_setup,path,"Saved Games",file_name,"sav"); ok=game_file_compress_save(path,err_str); progress_draw(100); free(game_file_data); // remember last map strcpy(game_file_last_save_name,strrchr(path,'/')); // finished progress_shutdown(); return(ok); }