('ent_challenge', 'Challenge', '', 18 )
]
+MDL_VERSION_NR = 102
+
def get_entity_enum_id( alias ):
#{
for et in sr_entity_list:#{
class ent_gate(Structure):
#{
- _fields_ = [("type",c_uint32),
+ _fields_ = [("flags",c_uint32),
("target", c_uint32),
("key",c_uint32),
("dimensions", c_float*3),
("_anonymous_union",version_refcount_union),
("timing_time",c_double),
("routes",c_uint16*4),
- ("route_count",c_uint8)]
+ ("route_count",c_uint8),
+ ("submesh_start",c_uint32), # v102+
+ ("submesh_count",c_uint32), # v102+ (can be 0)
+ ]
#}
class ent_route_node(Structure):
if ent_type == 'ent_font_variant': continue
if ent_type == 'ent_menuitem': continue
if ent_type == 'ent_challenge': continue
+
+ #TODO: This is messy.
+ if ent_type == 'ent_gate':#{
+ obj_data = obj.SR_data.ent_gate[0]
+ if obj_data.custom: continue
+ #}
#--------------------------
print( F'[SR] {i: 3}/{mesh_count} {obj.name:<40}', end='\r' )
obj_data = obj.SR_data.ent_gate[0]
mesh_data = obj.data.SR_data.ent_gate[0]
+ flags = 0x0000
+
if obj_data.tipo == 'default':#{
if obj_data.target:#{
gate.target = sr_compile.entity_ids[obj_data.target.name]
- gate.type = 1
+ flags |= 0x0001
#}
#}
elif obj_data.tipo == 'nonlocal':#{
gate.target = 0
gate.key = sr_compile_string(obj_data.key)
- gate.type = 2
+ flags |= 0x0002
+ #}
+
+ if obj_data.flip: flags |= 0x0004
+ if obj_data.custom:#{
+ flags |= 0x0008
+ gate.submesh_start, gate.submesh_count, _ = \
+ sr_compile_mesh_internal( obj )
#}
- else: gate.type = 0
+ gate.flags = flags
gate.dimensions[0] = mesh_data.dimensions[0]
gate.dimensions[1] = mesh_data.dimensions[1]
os.makedirs(os.path.dirname(path),exist_ok=True)
fp = open( path, "wb" )
header = mdl_header()
- header.version = 101
+ header.version = MDL_VERSION_NR
sr_array_title( header.arrays, \
'index', len(file_array_instructions), \
sizeof(mdl_array), header_size )
key: bpy.props.StringProperty()
tipo: bpy.props.EnumProperty(items=(('default', 'Default', ""),
- ('nonlocal', 'Non-Local', ""),))
+ ('nonlocal', 'Non-Local', "")))
+
+ flip: bpy.props.BoolProperty( name="Flip exit", default=False )
+ custom: bpy.props.BoolProperty( name="Mesh is surface", default=False )
@staticmethod
def sr_inspector( layout, data ):
if data[0].tipo == 'default': box.prop( data[0], 'target' )
elif data[0].tipo == 'nonlocal': box.prop( data[0], 'key' )
+
+ flags = box.box()
+ flags.prop( data[0], 'flip' )
+ flags.prop( data[0], 'custom' )
#}
#}
/*
* Update the transform matrices for gate
*/
-VG_STATIC void gate_transform_update( ent_gate *gate )
-{
+VG_STATIC void gate_transform_update( ent_gate *gate ){
+ if( gate->flags & k_ent_gate_flip ){
+ v4f qflip;
+ q_axis_angle( qflip, (v3f){0.0f,1.0f,0.0f}, VG_PIf );
+ q_mul( gate->q[1], qflip, gate->q[1] );
+ }
+
m4x3f to_local, recv_to_world;
q_m3x3( gate->q[0], gate->to_world );
q_m3x3( gate->q[1], recv_to_world );
v3_copy( gate->co[1], recv_to_world[3] );
m4x3_mul( recv_to_world, to_local, gate->transport );
-
- m3x3_scale( gate->to_world, (v3f){ gate->dimensions[0],
- gate->dimensions[1], 1.0f } );
}
VG_STATIC void world_gates_init(void)
/*
* Render the view through a gate
*/
-VG_STATIC int render_gate( world_instance *world_inside,
+VG_STATIC int render_gate( world_instance *world, world_instance *world_inside,
ent_gate *gate, camera *cam, int layer_depth )
{
v3f viewdir, gatedir;
return 0;
{
- v3f a,b,c,d;
+ f32 w = gate->dimensions[0],
+ h = gate->dimensions[1];
- m4x3_mulv( gate->to_world, (v3f){-1.0f,-1.0f,0.0f}, a );
- m4x3_mulv( gate->to_world, (v3f){ 1.0f,-1.0f,0.0f}, b );
- m4x3_mulv( gate->to_world, (v3f){ 1.0f, 1.0f,0.0f}, c );
- m4x3_mulv( gate->to_world, (v3f){-1.0f, 1.0f,0.0f}, d );
+ v3f a,b,c,d;
+ m4x3_mulv( gate->to_world, (v3f){-w,-h,0.0f}, a );
+ m4x3_mulv( gate->to_world, (v3f){ w,-h,0.0f}, b );
+ m4x3_mulv( gate->to_world, (v3f){ w, h,0.0f}, c );
+ m4x3_mulv( gate->to_world, (v3f){-w, h,0.0f}, d );
vg_line( a,b, 0xffffa000 );
vg_line( b,c, 0xffffa000 );
vg_line( c,d, 0xffffa000 );
vg_line( d,a, 0xffffa000 );
-
- vg_line2( gate->co[0], gate->co[1], 0xff0000ff, 0x00000000 );
+ vg_line( gate->co[0], gate->co[1], 0xff0000ff );
}
/* update gate camera */
{
shader_model_gate_use();
shader_model_gate_uPv( cam->mtx.pv );
- shader_model_gate_uMdl( gate->to_world );
shader_model_gate_uCam( cam->pos );
shader_model_gate_uColour( (v4f){0.0f,1.0f,0.0f,0.0f} );
shader_model_gate_uTime( vg.time*0.25f );
glStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE );
glStencilFunc( GL_ALWAYS, 1, 0xFF );
glStencilMask( 0xFF );
+ glDisable( GL_CULL_FACE );
+
+ m4x3f mmdl;
+ m4x3_copy( gate->to_world, mmdl );
+
+ if( gate->flags & k_ent_gate_custom_mesh ){
+ mesh_bind( &world->mesh_no_collide );
+ for( u32 i=0; i<gate->submesh_count; i++ ){
+ mdl_submesh *sm = mdl_arritm( &world->meta.submeshs,
+ gate->submesh_start+i );
+ mdl_draw_submesh( sm );
+ }
+ }
+ else {
+ m3x3_scale( mmdl, (v3f){ gate->dimensions[0],
+ gate->dimensions[1], 1.0f } );
+
+ mesh_bind( &world_gates.mesh );
+ mdl_draw_submesh( &world_gates.sm_surface );
+ }
- mesh_bind( &world_gates.mesh );
- mdl_draw_submesh( &world_gates.sm_surface );
+ shader_model_gate_uMdl( mmdl );
glClear( GL_DEPTH_BUFFER_BIT );
glStencilFunc( GL_EQUAL, 1, 0xFF );
glStencilMask( 0x00 );
+ glEnable( GL_CULL_FACE );
}
render_world( world_inside, &world_gates.cam, layer_depth );
v2f xy;
if( gate_intersect_plane( gate, pos, last, xy ) ){
- if( fabsf(xy[0]) <= 1.0f && fabsf(xy[1]) <= 1.0f ){
+ if( (fabsf(xy[0]) <= gate->dimensions[0]) &&
+ (fabsf(xy[1]) <= gate->dimensions[1]) ){
return 1;
}
}
* Intersect all gates in the world
*/
VG_STATIC ent_gate *world_intersect_gates( world_instance *world,
- v3f pos, v3f last )
-{
+ v3f pos, v3f last ){
for( u32 i=0; i<mdl_arrcount(&world->ent_gate); i++ ){
ent_gate *gate = mdl_arritm( &world->ent_gate, i );
- if( gate->type == k_gate_type_unlinked ||
- gate->type == k_gate_type_nonlocal_unlinked )
- continue;
- if( gate->type == k_gate_type_nonlocel ){
+ if( !(gate->flags & k_ent_gate_linked) ) continue;
+
+ if( gate->flags & k_ent_gate_nonlocal ){
if( world_loader.state != k_world_loader_none ){
continue;
}
/*
* detatches any nonlocal gates
*/
-VG_STATIC void world_unlink_nonlocal( world_instance *world )
-{
+VG_STATIC void world_unlink_nonlocal( world_instance *world ){
for( u32 j=0; j<mdl_arrcount(&world->ent_gate); j ++ ){
ent_gate *gate = mdl_arritm( &world->ent_gate, j );
- if( gate->type == k_gate_type_nonlocel ){
- gate->type = k_gate_type_nonlocal_unlinked;
+ if( gate->flags & k_ent_gate_nonlocal ){
+ gate->flags &= ~k_ent_gate_linked;
}
}
}
for( u32 j=0; j<mdl_arrcount(&world->ent_gate); j ++ ){
ent_gate *gate = mdl_arritm( &world->ent_gate, j );
- if( gate->type == k_gate_type_nonlocal_unlinked ){
- const char *key = mdl_pstr( &world->meta, gate->key );
- vg_info( "key: %s\n", key );
+ if( !(gate->flags & k_ent_gate_nonlocal) ) continue;
+ if( gate->flags & k_ent_gate_linked ) continue;
+
+ const char *key = mdl_pstr( &world->meta, gate->key );
+ vg_info( "key: %s\n", key );
+
+ for( u32 i=0; i<vg_list_size(world_static.worlds); i++ ){
+ world_instance *other = &world_static.worlds[i];
+ if( other == world ) continue;
+ if( other->status != k_world_status_loaded ) continue;
+ vg_info( "Checking world %u for key matches\n", i );
+
+ for( u32 j=0; j<mdl_arrcount( &other->ent_gate ); j++ ){
+ ent_gate *gate2 = mdl_arritm( &other->ent_gate, j );
- for( u32 i=0; i<vg_list_size(world_static.worlds); i++ ){
- world_instance *other = &world_static.worlds[i];
- if( other == world ) continue;
- if( other->status != k_world_status_loaded ) continue;
- vg_info( "Checking world %u for key matches\n", i );
+ if( !(gate2->flags & k_ent_gate_nonlocal) ) continue;
+ if( gate2->flags & k_ent_gate_linked ) continue;
- for( u32 j=0; j<mdl_arrcount( &other->ent_gate ); j++ ){
- ent_gate *gate2 = mdl_arritm( &other->ent_gate, j );
- if( gate2->type != k_gate_type_nonlocal_unlinked ) continue;
+ const char *key2 = mdl_pstr( &other->meta, gate2->key );
+ vg_info( " key2: %s\n", key2 );
- const char *key2 = mdl_pstr( &other->meta, gate2->key );
- vg_info( " key2: %s\n", key2 );
+ if( strcmp( key, key2 ) ) continue;
- if( strcmp( key, key2 ) ) continue;
+ vg_success( "Non-local matching pair '%s' found. (%u:%u)\n",
+ key, world_id, i );
- vg_success( "Non-local matching pair '%s' found. (%u:%u)\n",
- key, world_id, i );
-
- gate->type = k_gate_type_nonlocel;
- gate2->type = k_gate_type_nonlocel;
- gate->target = i;
- gate2->target = world_id;
+ gate->flags |= k_ent_gate_linked;
+ gate2->flags |= k_ent_gate_linked;
+ gate->target = i;
+ gate2->target = world_id;
- v3_copy( gate->co[0], gate2->co[1] );
- v3_copy( gate2->co[0], gate->co[1] );
- v4_copy( gate->q[0], gate2->q[1] );
- v4_copy( gate2->q[0], gate->q[1] );
+ v3_copy( gate->co[0], gate2->co[1] );
+ v3_copy( gate2->co[0], gate->co[1] );
+ v4_copy( gate->q[0], gate2->q[1] );
+ v4_copy( gate2->q[0], gate->q[1] );
+ if( other->meta.info.version >= 102 ){
+ gate->flags |= k_ent_gate_flip;
+ gate2->flags |= k_ent_gate_flip;
+ }
+ else {
+ /* LEGACY BEHAVIOUR: v101
+ * this would flip both the client worlds portal's entrance and
+ * exit. effectively the clients portal would be the opposite
+ * to the hub worlds one. new behaviour is to just flip the
+ * destinations so the rules are consistent in each world.
+ */
v4f qflip;
q_axis_angle( qflip, (v3f){0.0f,1.0f,0.0f}, VG_PIf );
q_mul( gate->q[0], qflip, gate->q[0] );
q_mul( gate->q[1], qflip, gate->q[1] );
+ }
- gate_transform_update( gate );
- gate_transform_update( gate2 );
+ gate_transform_update( gate );
+ gate_transform_update( gate2 );
- goto matched;
- }
+ goto matched;
}
-matched:;
}
+matched:;
}
}