revision 2
[carveJwlIkooP6JGAAIwe30JlM.git] / ent_miniworld.c
1 #include "entity.h"
2 #include "ent_miniworld.h"
3 #include "world_render.h"
4 #include "input.h"
5 #include "gui.h"
6 #include "menu.h"
7
8 struct global_miniworld global_miniworld;
9
10 void ent_miniworld_call( world_instance *world, ent_call *call )
11 {
12 ent_miniworld *miniworld = mdl_arritm( &world->ent_miniworld,
13 mdl_entity_id_id(call->id) );
14
15 int world_id = world - world_static.instances;
16
17 if( call->function == 0 ){ /* zone() */
18 const char *uid = mdl_pstr( &world->meta, miniworld->pstr_world );
19 skaterift_load_world_command( 1, (const char *[]){ uid } );
20
21 mdl_transform_m4x3( &miniworld->transform, global_miniworld.mmdl );
22 global_miniworld.active = miniworld;
23
24 gui_helper_clear();
25 vg_str text;
26
27 if( gui_new_helper( input_button_list[k_srbind_miniworld_resume], &text ))
28 vg_strcat( &text, "Enter World" );
29 }
30 else if( call->function == 1 ){
31 global_miniworld.active = NULL;
32 gui_helper_clear();
33
34 if( miniworld->proxy ){
35 ent_prop *prop = mdl_arritm( &world->ent_prop,
36 mdl_entity_id_id(miniworld->proxy) );
37 prop->flags &= ~0x1;
38 }
39 }
40 }
41
42 static void miniworld_icon( vg_camera *cam, enum gui_icon icon,
43 v3f pos, f32 size)
44 {
45 m4x3f mmdl;
46 v3_copy( cam->transform[2], mmdl[2] );
47 mmdl[2][1] = 0.0f;
48 v3_normalize( mmdl[2] );
49 v3_copy( (v3f){0,1,0}, mmdl[1] );
50 v3_cross( mmdl[1], mmdl[2], mmdl[0] );
51 m4x3_mulv( global_miniworld.mmdl, pos, mmdl[3] );
52
53 shader_model_font_uMdl( mmdl );
54 shader_model_font_uOffset( (v4f){0,0,0,20.0f*size} );
55
56 m4x4f m4mdl;
57 m4x3_expand( mmdl, m4mdl );
58 m4x4_mul( cam->mtx_prev.pv, m4mdl, m4mdl );
59 shader_model_font_uPvmPrev( m4mdl );
60
61 mdl_submesh *sm = gui.icons[ icon ];
62 if( sm )
63 mdl_draw_submesh( sm );
64 }
65
66 void ent_miniworld_render( world_instance *host_world, vg_camera *cam )
67 {
68 if( host_world != &world_static.instances[k_world_purpose_hub] )
69 return;
70
71 ent_miniworld *miniworld = global_miniworld.active;
72
73 if( !miniworld )
74 return;
75
76 world_instance *dest_world = &world_static.instances[k_world_purpose_client];
77
78 int rendering = 1;
79 if( dest_world->status != k_world_status_loaded )
80 rendering = 0;
81
82 if( miniworld->proxy ){
83 ent_prop *prop = mdl_arritm( &host_world->ent_prop,
84 mdl_entity_id_id(miniworld->proxy) );
85 if( !rendering )
86 prop->flags &= ~0x1;
87 else
88 prop->flags |= 0x1;
89 }
90
91
92 if( !rendering )
93 return;
94
95 render_world_override( dest_world, host_world, global_miniworld.mmdl, cam,
96 NULL, (v4f){dest_world->tar_min,10000.0f,0.0f,0.0f} );
97 render_world_routes( dest_world, host_world,
98 global_miniworld.mmdl, cam, 0, 1 );
99
100 /* icons
101 * ---------------------*/
102 font3d_bind( &gui.font, k_font_shader_default, 0, NULL, cam );
103 mesh_bind( &gui.icons_mesh );
104
105 glActiveTexture( GL_TEXTURE0 );
106 glBindTexture( GL_TEXTURE_2D, gui.icons_texture );
107 shader_model_font_uTexMain( 0 );
108 shader_model_font_uColour( (v4f){1,1,1,1} );
109
110 miniworld_icon( cam, k_gui_icon_player, dest_world->player_co,
111 1.0f + sinf(vg.time)*0.2f );
112
113 for( u32 i=0; i<mdl_arrcount(&dest_world->ent_challenge); i++ ){
114 ent_challenge *challenge = mdl_arritm( &dest_world->ent_challenge, i );
115
116 enum gui_icon icon = k_gui_icon_exclaim;
117 if( challenge->status )
118 icon = k_gui_icon_tick;
119
120 miniworld_icon( cam, icon, challenge->transform.co, 1.0f );
121 }
122
123 for( u32 i=0; i<mdl_arrcount(&dest_world->ent_route); i++ ){
124 ent_route *route = mdl_arritm( &dest_world->ent_route, i );
125
126 if( route->flags & k_ent_route_flag_achieve_gold ){
127 miniworld_icon( cam, k_gui_icon_rift_run_gold,
128 route->board_transform[3],1.0f);
129 }
130 else if( route->flags & k_ent_route_flag_achieve_silver ){
131 miniworld_icon( cam, k_gui_icon_rift_run_silver,
132 route->board_transform[3],1.0f);
133 }
134 }
135
136 for( u32 i=0; i<mdl_arrcount(&dest_world->ent_route); i++ ){
137 ent_route *route = mdl_arritm( &dest_world->ent_route, i );
138
139 v4f colour;
140 v4_copy( route->colour, colour );
141 v3_muls( colour, 1.6666f, colour );
142 shader_model_font_uColour( colour );
143 miniworld_icon( cam, k_gui_icon_rift_run, route->board_transform[3],1.0f);
144 }
145 }
146
147 void ent_miniworld_preupdate(void)
148 {
149 world_instance *hub = world_current_instance(),
150 *dest = &world_static.instances[k_world_purpose_client];
151
152 ent_miniworld *miniworld = global_miniworld.active;
153
154 if( (localplayer.subsystem != k_player_subsystem_walk) ||
155 (global_miniworld.transition) ||
156 (world_static.active_instance != k_world_purpose_hub) ||
157 (!miniworld) ||
158 (dest->status != k_world_status_loaded) ||
159 (skaterift.activity != k_skaterift_default)) {
160 return;
161 }
162
163 if( button_down( k_srbind_miniworld_resume ) ){
164 if( skaterift.demo_mode ){
165 if( world_static.instance_addons[1]->flags & ADDON_REG_PREMIUM ){
166 skaterift.activity = k_skaterift_menu;
167 menu.page = 0xffffffff;
168 menu_open_page( "Premium", k_ent_menuitem_stack_append );
169 return;
170 }
171 }
172
173 global_miniworld.transition = 1;
174 global_miniworld.t = 0.0f;
175 global_miniworld.cam = skaterift.cam;
176
177 world_switch_instance(1);
178 srinput.state = k_input_state_resume;
179 menu.disable_open = 0;
180 gui_helper_clear();
181 audio_lock();
182 audio_oneshot( &audio_ui[2], 1.0f, 0.0f );
183 audio_unlock();
184 }
185 }
186
187 void ent_miniworld_goback(void)
188 {
189 audio_lock();
190 audio_oneshot( &audio_ui[2], 1.0f, 0.0f );
191 audio_unlock();
192
193 global_miniworld.transition = -1;
194 global_miniworld.t = 1.0f;
195
196 global_miniworld.cam = skaterift.cam;
197 vg_m4x3_transform_camera( global_miniworld.mmdl, &global_miniworld.cam );
198 world_switch_instance(0);
199 }