basic npc
[carveJwlIkooP6JGAAIwe30JlM.git] / world_render.c
index 029a95f62e5f0279ba88004482a023acee683b20..1b1a9c08399d1d68020c58e37d673e18dc5748a2 100644 (file)
@@ -10,6 +10,7 @@
 #include "ent_miniworld.h"
 #include "player_remote.h"
 #include "ent_skateshop.h"
+#include "ent_npc.h"
 #include "shaders/model_entity.h"
 
 struct world_render world_render;
@@ -886,13 +887,16 @@ void world_prerender( world_instance *world )
                     sizeof(struct ub_world_lighting), &world->ub_lighting );
 }
 
-static void render_other_entities( world_instance *world, vg_camera *cam ){
+static void render_other_entities( world_instance *world, vg_camera *cam )
+{
    f32 radius = 40.0f;
    bh_iter it;
    bh_iter_init_range( 0, &it, cam->pos, radius+10.0f );
 
    u32 glider_list[4],
-       glider_count = 0;
+       glider_count = 0,
+       npc_list[4],
+       npc_count = 0;
 
    i32 idx;
    while( bh_next( world->entity_bh, &it, &idx ) ){
@@ -900,20 +904,26 @@ static void render_other_entities( world_instance *world, vg_camera *cam ){
           type  = mdl_entity_id_type( id ),
           index = mdl_entity_id_id( id );
 
-      if( type == k_ent_glider ) {
+      if( type == k_ent_glider ) 
+      {
          if( glider_count < vg_list_size(glider_list) )
             glider_list[ glider_count ++ ] = index;
       }
+      else if( type == k_ent_npc ) 
+      {
+         if( npc_count < vg_list_size(npc_list) )
+            npc_list[ npc_count ++ ] = index;
+      }
    }
 
    shader_model_entity_use();
    shader_model_entity_uTexMain( 0 );
    shader_model_entity_uCamera( cam->transform[3] );
    shader_model_entity_uPv( cam->mtx.pv );
-   
    WORLD_BIND_LIGHT_BUFFERS_UB0_TEX234( world, model_entity );
 
-   for( u32 j=0; j<glider_count; j ++ ){
+   for( u32 j=0; j<glider_count; j ++ )
+   {
       ent_glider *glider = mdl_arritm( &world->ent_glider, glider_list[j] );
 
       if( !(glider->flags & 0x1) )
@@ -928,6 +938,14 @@ static void render_other_entities( world_instance *world, vg_camera *cam ){
 
       render_glider_model( cam, world, mdl, k_board_shader_entity );
    }
+
+   for( u32 j=0; j<npc_count; j ++ )
+   {
+      u32 index = npc_list[j];
+      ent_npc *npc = mdl_arritm( &world->ent_npc, npc_list[j] );
+      npc_update( npc );
+      npc_render( npc, world, cam );
+   }
 }
 
 void render_world( world_instance *world, vg_camera *cam,