Skip to content

Commit

Permalink
vk: extract func_wall entities and ignore them
Browse files Browse the repository at this point in the history
This is part one for #415. Next parts will include merging these
entites/models back into static worldmodel.
  • Loading branch information
w23 committed Apr 13, 2023
1 parent b894337 commit f9389d8
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 3 deletions.
35 changes: 32 additions & 3 deletions ref/vk/vk_brush.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,11 @@ void VK_BrushModelDraw( const cl_entity_t *ent, int render_mode, float blend, co
return;
}

// func_wall models have no geometries and should be ignored
if (!bmodel->render_model.num_geometries) {
return;
}

if (render_mode == kRenderTransColor) {
Vector4Set(bmodel->render_model.color,
ent->curstate.rendercolor.r / 255.f,
Expand Down Expand Up @@ -682,12 +687,31 @@ static qboolean loadBrushSurfaces( model_sizes_t sizes, const model_t *mod ) {
return true;
}

static qboolean modelIsFuncWall( const model_t *const mod ) {
for (int i = 0; i < g_map_entities.func_walls_count; ++i) {
const xvk_mapent_func_wall_t *const fw = g_map_entities.func_walls + i;
if (Q_strcmp(mod->name, fw->model) == 0) {
return true;
}
}

return false;
}

qboolean VK_BrushModelLoad( model_t *mod ) {
if (mod->cache.data) {
gEngine.Con_Reportf( S_WARN "Model %s was already loaded\n", mod->name );
return true;
}

// Models referenced by func_wall entities are static and should be part of worldmodel
if (modelIsFuncWall(mod)) {
gEngine.Con_Reportf( "Model \"%s\" is func_wall, ignoring\n", mod->name);
vk_brush_model_t *bmodel = Mem_Calloc(vk_core.pool, sizeof(vk_brush_model_t));
mod->cache.data = bmodel;
return true;
}

gEngine.Con_Reportf("%s: %s flags=%08x\n", __FUNCTION__, mod->name, mod->flags);

{
Expand Down Expand Up @@ -765,6 +789,14 @@ static rt_light_add_polygon_t loadPolyLight(const model_t *mod, const int surfac
}

void R_VkBrushModelCollectEmissiveSurfaces( const struct model_s *mod, qboolean is_worldmodel ) {
vk_brush_model_t *const bmodel = mod->cache.data;
ASSERT(bmodel);

// Ignore func_wall models
if (!bmodel->render_model.num_geometries) {
return;
}

typedef struct {
int model_surface_index;
int surface_index;
Expand Down Expand Up @@ -809,9 +841,6 @@ void R_VkBrushModelCollectEmissiveSurfaces( const struct model_s *mod, qboolean
VectorCopy(emissive, surface->emissive);
}

vk_brush_model_t *const bmodel = mod->cache.data;
ASSERT(bmodel);

// Clear old per-geometry emissive values. The new emissive values will be assigned by the loop below only to the relevant geoms
for (int i = 0; i < bmodel->render_model.num_geometries; ++i) {
vk_render_geometry_t *const geom = bmodel->render_model.geometries + i;
Expand Down
27 changes: 27 additions & 0 deletions ref/vk/vk_mapents.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ static unsigned parseEntPropClassname(const char* value, class_name_e *out, unsi
*out = LightEnvironment;
} else if (Q_strcmp(value, "worldspawn") == 0) {
*out = Worldspawn;
} else if (Q_strcmp(value, "func_wall") == 0) {
*out = FuncWall;
} else {
*out = Ignored;
}
Expand Down Expand Up @@ -321,6 +323,23 @@ static void readWorldspawn( const entity_props_t *props ) {
Q_strcpy(g_map_entities.wadlist, props->wad);
}

static void readFuncWall( const entity_props_t *const props, uint32_t have_fields, int props_count ) {
gEngine.Con_Reportf("func_wall entity model=\"%s\", props_count=%d\n", (have_fields & Field_model) ? props->model : "N/A", props_count);

if (g_map_entities.func_walls_count >= MAX_FUNC_WALL_ENTITIES) {
gEngine.Con_Printf(S_ERROR "Too many func_wall entities, max supported = %d\n", MAX_FUNC_WALL_ENTITIES);
return;
}

xvk_mapent_func_wall_t *const e = g_map_entities.func_walls + (g_map_entities.func_walls_count++);

Q_strcpy(e->model, props->model);

// TODO:
// "renderamt" "255"
// "rendermode" "4"
}

static void addPatchSurface( const entity_props_t *props, uint32_t have_fields ) {
const model_t* const map = gEngine.pfnGetModelByIndex( 1 );
const int num_surfaces = map->numsurfaces;
Expand Down Expand Up @@ -437,6 +456,7 @@ static void addPatchEntity( const entity_props_t *props, uint32_t have_fields )

static void parseEntities( char *string ) {
unsigned have_fields = 0;
int props_count = 0;
entity_props_t values;
char *pos = string;
//gEngine.Con_Reportf("ENTITIES: %s\n", pos);
Expand All @@ -452,6 +472,7 @@ static void parseEntities( char *string ) {
if (key[0] == '{') {
have_fields = None;
values = (entity_props_t){0};
props_count = 0;
continue;
} else if (key[0] == '}') {
const int target_fields = Field_targetname | Field_origin;
Expand All @@ -468,6 +489,10 @@ static void parseEntities( char *string ) {
readWorldspawn( &values );
break;

case FuncWall:
readFuncWall( &values, have_fields, props_count );
break;

case Unknown:
if (have_fields & Field__xvk_surface_id) {
addPatchSurface( &values, have_fields );
Expand Down Expand Up @@ -500,6 +525,7 @@ static void parseEntities( char *string ) {
{
//gEngine.Con_Reportf("Unknown field %s with value %s\n", key, value);
}
++props_count;
#undef CHECK_FIELD
}
}
Expand Down Expand Up @@ -571,6 +597,7 @@ void XVK_ParseMapEntities( void ) {
g_map_entities.num_lights = 0;
g_map_entities.single_environment_index = NoEnvironmentLights;
g_map_entities.entity_count = 0;
g_map_entities.func_walls_count = 0;

parseEntities( map->entities );
orientSpotlights();
Expand Down
11 changes: 11 additions & 0 deletions ref/vk/vk_mapents.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
X(18, vec4_t, _xvk_tvec, Vec4) \
X(19, vec2_t, _xvk_tex_offset, Vec2) \
X(20, vec2_t, _xvk_tex_scale, Vec2) \
X(21, string, model, String) \

typedef enum {
Unknown = 0,
Light,
LightSpot,
LightEnvironment,
Worldspawn,
FuncWall,
Ignored,
} class_name_e;

Expand Down Expand Up @@ -78,6 +80,11 @@ typedef struct {

#define MAX_MAPENT_TARGETS 256

typedef struct {
string model;
// TODO rendermode, renderamt
} xvk_mapent_func_wall_t;

typedef struct {
int num_lights;
vk_light_entity_t lights[256];
Expand All @@ -89,6 +96,10 @@ typedef struct {

int num_targets;
xvk_mapent_target_t targets[MAX_MAPENT_TARGETS];

#define MAX_FUNC_WALL_ENTITIES 64
int func_walls_count;
xvk_mapent_func_wall_t func_walls[MAX_FUNC_WALL_ENTITIES];
} xvk_map_entities_t;

extern xvk_map_entities_t g_map_entities;
Expand Down

0 comments on commit f9389d8

Please sign in to comment.