2 #include "ent_miniworld.h"
3 #include "world_render.h"
8 static void miniworld_helper_default(void){
12 if( gui_new_helper( input_button_list
[k_srbind_miniworld_teleport
],&text
))
13 vg_strcat( &text
, "Teleport" );
15 if( gui_new_helper( input_button_list
[k_srbind_miniworld_resume
], &text
))
16 vg_strcat( &text
, "Enter World" );
19 static void miniworld_helper_tele(void){
22 if( gui_new_helper( input_button_list
[k_srbind_miniworld_resume
], &text
))
23 vg_strcat( &text
, "Confirm" );
25 if( gui_new_helper( input_button_list
[k_srbind_mback
],&text
))
26 vg_strcat( &text
, "Cancel" );
29 static void ent_miniworld_call( world_instance
*world
, ent_call
*call
){
30 ent_miniworld
*miniworld
= mdl_arritm( &world
->ent_miniworld
,
31 mdl_entity_id_id(call
->id
) );
33 int world_id
= world
- world_static
.instances
;
35 if( call
->function
== 0 ){ /* zone() */
36 const char *uid
= mdl_pstr( &world
->meta
, miniworld
->pstr_world
);
37 skaterift_load_world_command( 1, (const char *[]){ uid
} );
39 mdl_transform_m4x3( &miniworld
->transform
, global_miniworld
.mmdl
);
40 global_miniworld
.active
= miniworld
;
41 global_miniworld
.mode
= 0;
42 global_miniworld
.dest_spawn
= NULL
;
43 miniworld_helper_default();
45 else if( call
->function
== 1 ){
46 global_miniworld
.active
= NULL
;
47 global_miniworld
.mode
= 0;
48 global_miniworld
.dest_spawn
= NULL
;
51 if( miniworld
->proxy
){
52 ent_prop
*prop
= mdl_arritm( &world
->ent_prop
,
53 mdl_entity_id_id(miniworld
->proxy
) );
59 static void miniworld_icon( camera
*cam
, enum gui_icon icon
, v3f pos
, f32 size
){
61 v3_copy( cam
->transform
[2], mmdl
[2] );
63 v3_normalize( mmdl
[2] );
64 v3_copy( (v3f
){0,1,0}, mmdl
[1] );
65 v3_cross( mmdl
[1], mmdl
[2], mmdl
[0] );
66 m4x3_mulv( global_miniworld
.mmdl
, pos
, mmdl
[3] );
68 shader_model_font_uMdl( mmdl
);
69 shader_model_font_uOffset( (v4f
){0,0,0,20.0f
*size
} );
72 m4x3_expand( mmdl
, m4mdl
);
73 m4x4_mul( cam
->mtx_prev
.pv
, m4mdl
, m4mdl
);
74 shader_model_font_uPvmPrev( m4mdl
);
76 mdl_submesh
*sm
= gui
.icons
[ icon
];
78 mdl_draw_submesh( sm
);
81 static void ent_miniworld_render( world_instance
*host_world
, camera
*cam
){
82 if( host_world
!= &world_static
.instances
[k_world_purpose_hub
] )
85 ent_miniworld
*miniworld
= global_miniworld
.active
;
90 world_instance
*dest_world
= &world_static
.instances
[k_world_purpose_client
];
93 if( dest_world
->status
!= k_world_status_loaded
)
96 if( miniworld
->proxy
){
97 ent_prop
*prop
= mdl_arritm( &host_world
->ent_prop
,
98 mdl_entity_id_id(miniworld
->proxy
) );
109 render_world_override( dest_world
, host_world
, global_miniworld
.mmdl
, cam
,
110 global_miniworld
.dest_spawn
);
111 render_world_routes( dest_world
, host_world
,
112 global_miniworld
.mmdl
, cam
, 0, 1 );
115 * ---------------------*/
116 font3d_bind( &gui
.font
, k_font_shader_default
, 0, NULL
, cam
);
117 mesh_bind( &gui
.icons_mesh
);
119 glActiveTexture( GL_TEXTURE0
);
120 glBindTexture( GL_TEXTURE_2D
, gui
.icons_texture
);
121 shader_model_font_uTexMain( 0 );
122 shader_model_font_uColour( (v4f
){1,1,1,1} );
124 miniworld_icon( cam
, k_gui_icon_player
, dest_world
->player_co
,
125 1.0f
+ sinf(vg
.time
)*0.2f
);
127 for( u32 i
=0; i
<mdl_arrcount(&dest_world
->ent_challenge
); i
++ ){
128 ent_challenge
*challenge
= mdl_arritm( &dest_world
->ent_challenge
, i
);
130 enum gui_icon icon
= k_gui_icon_exclaim
;
131 if( challenge
->status
)
132 icon
= k_gui_icon_tick
;
134 miniworld_icon( cam
, icon
, challenge
->transform
.co
, 1.0f
);
137 for( u32 i
=0; i
<mdl_arrcount(&dest_world
->ent_route
); i
++ ){
138 ent_route
*route
= mdl_arritm( &dest_world
->ent_route
, i
);
141 v4_copy( route
->colour
, colour
);
142 v3_muls( colour
, 1.6666f
, colour
);
143 shader_model_font_uColour( colour
);
144 miniworld_icon( cam
, k_gui_icon_rift_run
, route
->board_transform
[3],1.0f
);
148 static void ent_miniworld_preupdate(void){
149 world_instance
*hub
= world_current_instance(),
150 *dest
= &world_static
.instances
[k_world_purpose_client
];
152 ent_miniworld
*miniworld
= global_miniworld
.active
;
154 if( (localplayer
.subsystem
!= k_player_subsystem_walk
) ||
155 (global_miniworld
.transition
) ||
156 (world_static
.active_instance
!= k_world_purpose_hub
) ||
158 (dest
->status
!= k_world_status_loaded
) ){
160 if( global_miniworld
.mode
){
161 global_miniworld
.mode
= 0;
162 global_miniworld
.dest_spawn
= 0;
163 menu
.disable_open
= 0;
164 srinput
.state
= k_input_state_resume
;
170 if( button_down( k_srbind_miniworld_resume
) ){
171 global_miniworld
.mode
= 0;
172 global_miniworld
.transition
= 1;
173 global_miniworld
.t
= 0.0f
;
174 global_miniworld
.cam
= skaterift
.cam
;
176 if( global_miniworld
.dest_spawn
){
177 v3_copy( global_miniworld
.dest_spawn
->transform
.co
,
181 world_switch_instance(1);
182 global_miniworld
.dest_spawn
= NULL
;
183 srinput
.state
= k_input_state_resume
;
184 menu
.disable_open
= 0;
187 audio_oneshot( &audio_ui
[2], 1.0f
, 0.0f
);
191 if( global_miniworld
.mode
== 1 ){
192 if( button_down(k_srbind_mback
) ){
193 global_miniworld
.mode
= 0;
194 global_miniworld
.dest_spawn
= NULL
;
195 menu
.disable_open
= 0;
196 srinput
.state
= k_input_state_resume
;
197 miniworld_helper_default();
201 m4x3_invert_full( global_miniworld
.mmdl
, mmdl_inv
);
203 m4x3_mulv( mmdl_inv
, localplayer
.rb
.co
, lco
);
204 global_miniworld
.dest_spawn
= world_find_closest_spawn( dest
, lco
);
208 if( button_down( k_srbind_miniworld_teleport
) ){
209 global_miniworld
.mode
= 1;
210 menu
.disable_open
= 1;
211 miniworld_helper_tele();
217 static void ent_miniworld_goback(void){
219 audio_oneshot( &audio_ui
[2], 1.0f
, 0.0f
);
222 global_miniworld
.transition
= -1;
223 global_miniworld
.t
= 1.0f
;
225 global_miniworld
.cam
= skaterift
.cam
;
226 m4x3_transform_camera( global_miniworld
.mmdl
, &global_miniworld
.cam
);
227 world_switch_instance(0);