9 struct world_map world_map
;
11 static void world_map_get_dir( v3f dir
)
14 dir
[0] = -sqrtf(0.5f
);
20 static void world_map_get_plane( v4f plane
)
22 world_instance
*world
= &world_static
.instances
[ world_map
.world_id
];
23 f32 h
= localplayer
.rb
.co
[1];
24 if( world_map
.world_id
!= world_static
.active_instance
)
25 h
= (world
->scene_geo
.bbx
[0][1] + world
->scene_geo
.bbx
[1][1]) * 0.5f
;
27 v4_copy( (v4f
){0.0f
,1.0f
,0.0f
,h
}, plane
);
30 static void respawn_world_to_plane_pos( v3f pos
, v2f plane_pos
)
33 world_map_get_dir( dir
);
36 world_map_get_plane( plane
);
39 f32 t
= ray_plane( plane
, pos
, dir
);
40 v3_muladds( pos
, dir
, t
, co
);
45 static void respawn_map_draw_icon( vg_camera
*cam
,
46 enum gui_icon icon
, v3f pos
, f32 size
)
51 m4x4_mulv( cam
->mtx
.pv
, v
, v
);
52 v2_divs( v
, v
[3], v
);
54 gui_draw_icon( icon
, (v2f
){ v
[0]*0.5f
+0.5f
,v
[1]*0.5f
+0.5f
}, size
);
57 static void world_map_select_close(void)
59 world_map
.sel_spawn
= world_map
.close_spawn
;
63 if( gui_new_helper( input_button_list
[k_srbind_maccept
], &text
) )
64 vg_strcat( &text
, "Spawn Here" );
65 if( gui_new_helper( input_button_list
[k_srbind_mback
], &text
) )
66 vg_strcat( &text
, "Back" );
69 void world_map_click(void)
71 world_map_select_close();
74 static void world_map_help_normal(void)
79 if( gui_new_helper( input_joy_list
[k_srjoystick_steer
], &text
) )
80 vg_strcat( &text
, "Move" );
82 if( gui_new_helper( input_button_list
[k_srbind_maccept
], &text
) )
83 vg_strcat( &text
, "Select" );
85 if( gui_new_helper( input_button_list
[k_srbind_mback
], &text
) )
86 vg_strcat( &text
, "Exit" );
88 if( world_static
.instances
[1].status
== k_world_status_loaded
)
90 if( gui_new_helper( input_button_list
[k_srbind_mhub
], &text
) )
91 vg_strcat( &text
, world_static
.active_instance
?
92 "Go to Hub": "Go to Active World" );
96 void world_map_pre_update(void)
98 if( menu_viewing_map() )
100 if( !world_map
.view_ready
)
102 world_map
.world_id
= world_static
.active_instance
;
104 world_instance
*world
= &world_static
.instances
[ world_map
.world_id
];
105 v3f
*bbx
= world
->scene_geo
.bbx
;
107 v3_copy( localplayer
.rb
.co
, world
->player_co
);
108 respawn_world_to_plane_pos( localplayer
.rb
.co
, world_map
.plane_pos
);
109 world_map
.boom_dist
= 400.0f
;
110 world_map
.home_select
= 0;
111 world_map
.view_ready
= 1;
112 world_map
.sel_spawn
= NULL
;
113 world_map
.close_spawn
= NULL
;
115 world_map_help_normal();
120 if( world_map
.view_ready
)
123 world_map
.view_ready
= 0;
129 world_instance
*world
= &world_static
.instances
[ world_map
.world_id
];
130 v3f
*bbx
= world
->scene_geo
.bbx
;
131 f32
*pos
= world_map
.plane_pos
;
134 joystick_state( k_srjoystick_steer
, steer
);
135 v2_normalize_clamp( steer
);
137 if( !world_map
.sel_spawn
)
139 f32
*pos
= world_map
.plane_pos
;
141 m2x2_create_rotation( rm
, -0.25f
*VG_PIf
);
142 m2x2_mulv( rm
, steer
, steer
);
143 v2_muladds( pos
, steer
, vg
.time_frame_delta
* 200.0f
, pos
);
146 f32 bd_target
= 400.0f
,
147 interp
= vg
.time_frame_delta
*2.0f
;
149 if( world_map
.sel_spawn
)
152 respawn_world_to_plane_pos( world_map
.sel_spawn
->transform
.co
, pp
);
153 v2_lerp( pos
, pp
, interp
, pos
);
157 world_map
.boom_dist
= vg_lerpf( world_map
.boom_dist
, bd_target
, interp
);
159 v2_minv( (v2f
){ bbx
[1][0], bbx
[1][2] }, pos
, pos
);
160 v2_maxv( (v2f
){ bbx
[0][0], bbx
[0][2] }, pos
, pos
);
163 vg_camera
*cam
= &world_map
.cam
;
165 world_map_get_dir(dir
);
168 world_map_get_plane( plane
);
170 v3f co
= { pos
[0], plane
[3]*plane
[1], pos
[1] };
171 v3_muladds( co
, dir
, world_map
.boom_dist
, cam
->pos
);
173 vg_line_cross( co
, VG__RED
, 10.0f
);
175 cam
->angles
[0] = 0.25f
* VG_PIf
;
176 cam
->angles
[1] = 0.25f
* VG_PIf
;
181 vg_camera_update_transform( cam
);
182 vg_camera_update_view( cam
);
183 vg_camera_update_projection( cam
);
184 vg_camera_finalize( cam
);
187 f32 closest2
= INFINITY
;
188 v2f centroid
= { 0, 0 };
190 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_spawn
); i
++ )
192 ent_spawn
*spawn
= mdl_arritm(&world
->ent_spawn
,i
);
195 v3_copy( spawn
->transform
.co
, v
);
197 m4x4_mulv( cam
->mtx
.pv
, v
, v
);
198 v2_divs( v
, v
[3], v
);
200 f32 d2
= v2_dist2(v
, centroid
);
203 world_map
.close_spawn
= spawn
;
206 spawn
->transform
.s
[0] = d2
;
209 if( button_down( k_srbind_maccept
) )
211 if( world_map
.sel_spawn
)
213 skaterift
.activity
= k_skaterift_default
;
214 world_static
.active_instance
= world_map
.world_id
;
215 srinput
.state
= k_input_state_resume
;
216 player__spawn( world_map
.sel_spawn
);
221 world_map_select_close();
225 if( button_down( k_srbind_mback
) )
227 if( world_map
.sel_spawn
)
229 world_map
.sel_spawn
= NULL
;
230 world_map_help_normal();
234 srinput
.state
= k_input_state_resume
;
235 skaterift
.activity
= k_skaterift_default
;
241 * ---------------------*/
242 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_challenge
); i
++ )
244 ent_challenge
*challenge
= mdl_arritm( &world
->ent_challenge
, i
);
246 enum gui_icon icon
= k_gui_icon_exclaim_2d
;
247 if( challenge
->status
)
248 icon
= k_gui_icon_tick_2d
;
250 respawn_map_draw_icon( cam
, icon
, challenge
->transform
.co
, 1.0f
);
253 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_spawn
); i
++ )
255 ent_spawn
*spawn
= mdl_arritm( &world
->ent_spawn
, i
);
257 if( spawn
->transform
.s
[0] > 0.3f
)
260 f32 s
= 1.0f
-(spawn
->transform
.s
[0] / 0.3f
);
261 respawn_map_draw_icon( cam
,
262 spawn
==world_map
.sel_spawn
?
263 k_gui_icon_spawn_select
: k_gui_icon_spawn
,
264 spawn
->transform
.co
, s
);
267 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_skateshop
); i
++ )
269 ent_skateshop
*shop
= mdl_arritm( &world
->ent_skateshop
, i
);
270 if( shop
->type
== k_skateshop_type_boardshop
)
272 respawn_map_draw_icon( cam
, k_gui_icon_board
, shop
->transform
.co
, 1 );
274 else if( shop
->type
== k_skateshop_type_worldshop
)
276 respawn_map_draw_icon( cam
, k_gui_icon_world
, shop
->transform
.co
, 1 );
280 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_gate
); i
++ )
282 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, i
);
283 if( gate
->flags
& k_ent_gate_nonlocal
)
285 respawn_map_draw_icon( cam
, k_gui_icon_rift
, gate
->co
[0], 1 );
289 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ )
291 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
294 v4_copy( route
->colour
, colour
);
295 v3_muls( colour
, 1.6666f
, colour
);
296 gui_icon_setcolour( colour
);
297 respawn_map_draw_icon( cam
, k_gui_icon_rift_run_2d
,
298 route
->board_transform
[3], 1 );
301 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_glider
); i
++ )
303 ent_glider
*glider
= mdl_arritm( &world
->ent_glider
, i
);
305 v4f colour
= { 1,1,1,1 };
307 if( !(glider
->flags
& 0x1) )
308 v3_muls( colour
, 0.5f
, colour
);
309 gui_icon_setcolour( colour
);
311 respawn_map_draw_icon( cam
, k_gui_icon_glider
, glider
->transform
.co
, 1 );