[scene] Make entity_t just an entity id for ECS

This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).

While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
This commit is contained in:
Bill Currie 2022-10-23 10:32:09 +09:00
parent dd1554aed3
commit 8acd5c558b
104 changed files with 1410 additions and 1076 deletions

View file

@ -39,6 +39,6 @@ typedef struct aliasvrt_s {
} aliasvrt_t;
struct entity_s;
void gl_R_DrawAliasModel (struct entity_s *ent);
void gl_R_DrawAliasModel (struct entity_s ent);
#endif//__QF_GL_qf_alias_h

View file

@ -45,6 +45,6 @@ typedef struct glsliqm_s {
} gliqm_t;
struct entity_s;
void gl_R_DrawIQMModel (struct entity_s *ent);
void gl_R_DrawIQMModel (struct entity_s ent);
#endif//__QF_GL_qf_iqm_h

View file

@ -52,7 +52,7 @@ void GL_BuildLightmaps (struct model_s **models, int num_models);
void gl_R_BlendLightmaps (void);
void gl_R_CalcLightmaps (void);
struct transform_s;
extern void (*gl_R_BuildLightMap) (const struct transform_s *transform,
extern void (*gl_R_BuildLightMap) (const vec4f_t *transform,
mod_brush_t *brush, msurface_t *surf);
int gl_R_LightmapTexture (void) __attribute__((pure));
void gl_R_FlushLightmaps (void);

View file

@ -29,6 +29,7 @@
#define __QF_GL_rmain_h
#include "QF/qtypes.h"
#include "QF/simd/types.h"
struct cvar_s;
struct entity_s;
@ -41,7 +42,7 @@ extern float gl_modelalpha;
extern void gl_multitexture_f (void *data, const struct cvar_s *var);
void glrmain_init (void);
void gl_R_RotateForEntity (struct entity_s *e);
void gl_R_RotateForEntity (const vec4f_t *mat);
struct model_s;
struct entqueue_s;

View file

@ -44,7 +44,7 @@ struct mod_brush_s;
void GL_BuildSurfaceDisplayList (struct mod_brush_s *brush,
struct msurface_s *fa);
void gl_R_DrawBrushModel (struct entity_s *e);
void gl_R_DrawBrushModel (struct entity_s e);
void gl_R_DrawWorld (void);
void gl_R_DrawWaterSurfaces (void);

View file

@ -32,6 +32,6 @@
struct entity_s;
void gl_R_InitSprites (void);
extern void (*gl_R_DrawSpriteModel) (struct entity_s *ent);
extern void (*gl_R_DrawSpriteModel) (struct entity_s ent);
#endif//__QF_GL_qf_sprite_h

View file

@ -40,7 +40,7 @@ typedef struct aliasvrt_s {
void glsl_R_InitAlias (void);
struct entity_s;
void glsl_R_DrawAlias (struct entity_s *ent);
void glsl_R_DrawAlias (struct entity_s ent);
void glsl_R_AliasBegin (void);
void glsl_R_AliasEnd (void);

View file

@ -30,6 +30,7 @@
#ifndef __QF_GLSL_qf_bsp_h
#define __QF_GLSL_qf_bsp_h
#include "QF/simd/types.h"
#include "QF/GLSL/types.h"
typedef struct glsltex_s {
@ -59,7 +60,7 @@ typedef struct elechain_s {
struct elechain_s *next;
int model_index;
elements_t *elements;
vec_t *transform;
vec4f_t *transform;
float *color;
} elechain_t;

View file

@ -41,7 +41,7 @@ typedef struct glsliqm_s {
void glsl_R_InitIQM (void);
struct entity_s;
void glsl_R_DrawIQM (struct entity_s *ent);
void glsl_R_DrawIQM (struct entity_s ent);
void glsl_R_IQMBegin (void);
void glsl_R_IQMEnd (void);

View file

@ -37,7 +37,7 @@ void glsl_lightmap_init (void);
struct transform_s;
void glsl_R_BuildLightmaps (struct model_s **models, int num_models);
void glsl_R_CalcLightmaps (void);
extern void (*glsl_R_BuildLightMap) (const struct transform_s *transform,
extern void (*glsl_R_BuildLightMap) (const vec4f_t *transform,
mod_brush_t *brush, msurface_t *surf);
int glsl_R_LightmapTexture (void) __attribute__((pure));
void glsl_R_FlushLightmaps (void);

View file

@ -31,7 +31,7 @@
#define __QF_GLSL_qf_sprite_h
struct entity_s;
void glsl_R_DrawSprite (struct entity_s *ent);
void glsl_R_DrawSprite (struct entity_s ent);
void glsl_R_SpriteBegin (void);
void glsl_R_SpriteEnd (void);
void glsl_R_InitSprites (void);

View file

@ -108,7 +108,7 @@ void Vulkan_AliasAddSkin (struct vulkan_ctx_s *ctx, qfv_alias_skin_t *skin);
void Vulkan_AliasRemoveSkin (struct vulkan_ctx_s *ctx, qfv_alias_skin_t *skin);
void Vulkan_AliasBegin (struct qfv_renderframe_s *rFrame);
void Vulkan_DrawAlias (struct entity_s *ent, struct qfv_renderframe_s *rFrame);
void Vulkan_DrawAlias (struct entity_s ent, struct qfv_renderframe_s *rFrame);
void Vulkan_AliasEnd (struct qfv_renderframe_s *rFrame);
void Vulkan_Alias_Init (struct vulkan_ctx_s *ctx);

View file

@ -112,7 +112,7 @@ void Vulkan_IQMAddSkin (struct vulkan_ctx_s *ctx, qfv_iqm_skin_t *skin);
void Vulkan_IQMRemoveSkin (struct vulkan_ctx_s *ctx, qfv_iqm_skin_t *skin);
void Vulkan_IQMBegin (struct qfv_renderframe_s *rFrame);
void Vulkan_DrawIQM (struct entity_s *ent, struct qfv_renderframe_s *rFrame);
void Vulkan_DrawIQM (struct entity_s ent, struct qfv_renderframe_s *rFrame);
void Vulkan_IQMEnd (struct qfv_renderframe_s *rFrame);
void Vulkan_IQM_Init (struct vulkan_ctx_s *ctx);

View file

@ -75,7 +75,7 @@ void Vulkan_Scene_Init (struct vulkan_ctx_s *ctx);
void Vulkan_Scene_Shutdown (struct vulkan_ctx_s *ctx);
int Vulkan_Scene_MaxEntities (struct vulkan_ctx_s *ctx) __attribute__((pure));
VkDescriptorSet Vulkan_Scene_Descriptors (struct vulkan_ctx_s *ctx) __attribute__((pure));
int Vulkan_Scene_AddEntity (struct vulkan_ctx_s *ctx, struct entity_s *entity);
int Vulkan_Scene_AddEntity (struct vulkan_ctx_s *ctx, struct entity_s entity);
void Vulkan_Scene_Flush (struct vulkan_ctx_s *ctx);
#endif//__QF_Vulkan_qf_scene_h

View file

@ -89,7 +89,7 @@ void Vulkan_Mod_SpriteLoadFrames (struct mod_sprite_ctx_s *sprite_ctx,
struct vulkan_ctx_s *ctx);
void Vulkan_SpriteBegin (struct qfv_renderframe_s *rFrame);
void Vulkan_DrawSprite (struct entity_s *ent, struct qfv_renderframe_s *rFrame);
void Vulkan_DrawSprite (struct entity_s ent, struct qfv_renderframe_s *rFrame);
void Vulkan_SpriteEnd (struct qfv_renderframe_s *rFrame);
void Vulkan_Sprite_Init (struct vulkan_ctx_s *ctx);

View file

@ -91,7 +91,7 @@ VkDescriptorSetLayout Vulkan_CreateDescriptorSetLayout(struct vulkan_ctx_s*ctx,
struct entity_s;
void Vulkan_BeginEntityLabel (struct vulkan_ctx_s *ctx, VkCommandBuffer cmd,
struct entity_s *ent);
struct entity_s ent);
struct plitem_s *Vulkan_GetConfig (struct vulkan_ctx_s *ctx, const char *name);

View file

@ -56,13 +56,6 @@ extern struct vid_model_funcs_s *mod_funcs;
// BRUSH MODELS ===============================================================
typedef struct efrag_s {
struct mleaf_s *leaf;
struct efrag_s *leafnext;
struct entity_s *entity;
struct efrag_s *entnext;
} efrag_t;
// in memory representation ===================================================
// !!! if this is changed, it must be changed in asm_draw.h too !!!
@ -86,7 +79,7 @@ typedef struct instsurf_s {
struct instsurf_s *tex_chain; ///< next in texture chain
struct instsurf_s *lm_chain; ///< next in lightmap chain
struct msurface_s *surface; ///< surface to render
vec_t *transform;
vec4f_t *transform;
float *color;
} instsurf_t;
@ -199,7 +192,7 @@ typedef struct mleaf_s {
// leaf specific
byte *compressed_vis;
efrag_t *efrags;
struct efrag_s *efrags;
int firstmarksurface;
int nummarksurfaces;

View file

@ -55,7 +55,7 @@ typedef struct snd_render_funcs_s {
struct sfx_s *(*precache_sound) (const char *sample);
struct sfx_s *(*load_sound) (const char *name);
void (*update) (struct transform_s *ear,
void (*update) (struct transform_s ear,
const byte *ambient_sound_levels);
void (*stop_all_sounds) (void);
void (*extra_update) (void);

View file

@ -33,6 +33,8 @@
#include <QF/render.h>
#include <QF/screen.h>
#include "QF/scene/entity.h"//FIXME
struct plitem_s;
struct cvar_s;
struct scene_s;
@ -154,7 +156,7 @@ typedef struct vid_render_data_s {
qboolean inhibit_viewmodel;
qboolean paused;
int lineadj;
struct entity_s *view_model;
entity_t view_model; //FIXME still?!?
double frametime;
double realtime;
lightstyle_t *lightstyle;

View file

@ -166,6 +166,7 @@ typedef struct {
int ambientlight;
int drawflat;
struct scene_s *scene;
struct model_s *worldmodel;
} refdef_t;

View file

@ -33,6 +33,7 @@
#include "QF/qtypes.h"
#include "QF/simd/mat4f.h"
#include "QF/scene/transform.h"
/** \defgroup scene_camera Camera data
\ingroup scene
@ -43,7 +44,7 @@ typedef struct camera_s {
struct scene_s *scene; ///< owning scene
struct framebuffer_s *framebuffer;
int32_t id; ///< id in scene
int32_t transform;
transform_t transform;
float field_of_view;
float aspect;
float near_clip;

View file

@ -83,15 +83,17 @@ COMPINLINE void Component_CopyElements (const component_t *component,
void *dstArray, uint32_t dstIndex,
const void *srcArray, uint32_t srcIndex,
uint32_t count);
COMPINLINE void Component_CreateElements (const component_t *component,
void *array,
uint32_t index, uint32_t count);
COMPINLINE void *Component_CreateElements (const component_t *component,
void *array,
uint32_t index, uint32_t count);
COMPINLINE void Component_DestroyElements (const component_t *component,
void *array,
uint32_t index, uint32_t count);
COMPINLINE uint32_t Ent_Index (uint32_t id);
COMPINLINE uint32_t Ent_Generation (uint32_t id);
COMPINLINE uint32_t Ent_NextGen (uint32_t id);
COMPINLINE int ECS_EntValid (uint32_t id, ecs_registry_t *reg);
COMPINLINE int Ent_HasComponent (uint32_t ent, uint32_t comp,
ecs_registry_t *reg);
COMPINLINE void *Ent_GetComponent (uint32_t ent, uint32_t comp,
@ -132,7 +134,7 @@ Component_CopyElements (const component_t *component,
memcpy (dst, src, count * component->size);
}
COMPINLINE void
COMPINLINE void *
Component_CreateElements (const component_t *component, void *array,
uint32_t index, uint32_t count)
{
@ -145,6 +147,7 @@ Component_CreateElements (const component_t *component, void *array,
__auto_type dst = (byte *) array + index * component->size;
memset (dst, 0, count * component->size);
}
return (byte *) array + index * component->size;
}
COMPINLINE void
@ -177,6 +180,13 @@ Ent_NextGen(uint32_t id)
return id + (1 << ENT_IDBITS);
}
COMPINLINE int
ECS_EntValid (uint32_t id, ecs_registry_t *reg)
{
uint32_t ind = Ent_Index (id);
return ind < reg->num_entities && reg->entities[ind] == id;
}
COMPINLINE int
Ent_HasComponent (uint32_t ent, uint32_t comp, ecs_registry_t *reg)
{
@ -201,7 +211,7 @@ void ECS_RegisterComponents (ecs_registry_t *registry,
uint32_t ECS_NewEntity (ecs_registry_t *registry);
void ECS_DelEntity (ecs_registry_t *registry, uint32_t ent);
void Ent_AddComponent (uint32_t ent, uint32_t comp, ecs_registry_t *registry);
void *Ent_AddComponent (uint32_t ent, uint32_t comp, ecs_registry_t *registry);
void Ent_RemoveComponent (uint32_t ent, uint32_t comp,
ecs_registry_t *registry);

View file

@ -42,9 +42,16 @@
*/
///@{
#include "QF/scene/hierarchy.h"
#include "QF/scene/scene.h"
#include "QF/scene/transform.h"
typedef struct entity_s {
ecs_registry_t *reg;
uint32_t id;
} entity_t;
#define nullentity ((entity_t) {})
typedef struct animation_s {
int frame;
float syncbase; // randomize time base for local animations
@ -57,7 +64,6 @@ typedef struct animation_s {
} animation_t;
typedef struct visibility_s {
struct entity_s *entity; // owning entity
struct efrag_s *efrag; // linked list of efrags
int topnode_id; // bmodels, first world node that
// splits bmodel, or NULL if not split
@ -74,20 +80,18 @@ typedef struct renderer_s {
int fullbright;
float min_light;
int render_id;
mat4_t full_transform;
mat4f_t full_transform;
} renderer_t;
typedef struct entity_s {
struct entity_s *next;
struct transform_s *transform;
int id; ///< scene id
animation_t animation;
visibility_t visibility;
renderer_t renderer;
int active;
//XXX FIXME XXX should not be here
vec4f_t old_origin;
} entity_t;
typedef struct entityset_s DARRAY_TYPE (entity_t) entityset_t;
typedef struct efrag_s {
struct mleaf_s *leaf;
struct efrag_s *leafnext;
entity_t entity;
uint32_t queue_num;
struct efrag_s *entnext;
} efrag_t;
typedef struct entqueue_s {
set_t *queued_ents;
@ -99,9 +103,11 @@ typedef struct entqueue_s {
entqueue_t *EntQueue_New (int num_queues);
void EntQueue_Delete (entqueue_t *queue);
ENTINLINE void EntQueue_AddEntity (entqueue_t *queue, entity_t *ent,
ENTINLINE void EntQueue_AddEntity (entqueue_t *queue, entity_t ent,
int queue_num);
void EntQueue_Clear (entqueue_t *queue);
ENTINLINE int Entity_Valid (entity_t ent);
ENTINLINE transform_t Entity_Transform (entity_t ent);
#undef ENTINLINE
#ifndef IMPLEMENT_ENTITY_Funcs
@ -112,18 +118,35 @@ void EntQueue_Clear (entqueue_t *queue);
ENTINLINE
void
EntQueue_AddEntity (entqueue_t *queue, entity_t *ent, int queue_num)
EntQueue_AddEntity (entqueue_t *queue, entity_t ent, int queue_num)
{
int id = ~ent->id;
int id = Ent_Index (ent.id);
if (!set_is_member (queue->queued_ents, id)) {
// entity ids are negative (ones-complement)
set_add (queue->queued_ents, id);
DARRAY_APPEND (&queue->ent_queues[queue_num], ent);
}
}
ENTINLINE
int
Entity_Valid (entity_t ent)
{
return ent.reg && ECS_EntValid (ent.id, ent.reg);
}
ENTINLINE
transform_t
Entity_Transform (entity_t ent)
{
// The transform hierarchy reference is a component on the entity thus
// the entity id is the transform id.
return (transform_t) { .reg = ent.reg, .id = ent.id, .comp = scene_href };
}
struct mod_brush_s;
void R_AddEfrags (struct mod_brush_s *, entity_t *ent);
void R_RemoveEfrags (entity_t *ent);
void R_AddEfrags (struct mod_brush_s *, entity_t ent);
void R_RemoveEfrags (entity_t ent);
///@}

View file

@ -52,7 +52,6 @@ typedef struct hierarchy_type_s {
typedef struct hierref_s {
struct hierarchy_s *hierarchy;
uint32_t index; ///< index in hierarchy
int32_t id; ///< scene id
} hierref_t;
typedef struct hierarchy_s {
@ -61,8 +60,7 @@ typedef struct hierarchy_s {
struct scene_s *scene;
uint32_t num_objects;
uint32_t max_objects;
hierref_t **ref;
struct entity_s **entity; //FIXME should not exist
uint32_t *ent;
uint32_t *childCount;
uint32_t *childIndex;
uint32_t *parentIndex;

View file

@ -40,9 +40,23 @@
*/
///@{
enum scene_components {
scene_href, //hierarchical transform
scene_animation,
scene_visibility,
scene_renderer,
scene_active,
scene_old_origin, //XXX FIXME XXX should not be here
scene_num_components
};
typedef struct scene_s {
struct ecs_registry_s *reg;
struct scene_resources_s *const resources;
struct hierarchy_s *hierarchies;
struct model_s *worldmodel;
int num_models;
struct model_s **models;
@ -52,10 +66,8 @@ typedef struct scene_s {
scene_t *Scene_NewScene (void);
void Scene_DeleteScene (scene_t *scene);
struct entity_s *Scene_CreateEntity (scene_t *scene);
struct entity_s *Scene_GetEntity (scene_t *scene, int id) __attribute__((pure));
struct transform_s *Scene_GetTransform (scene_t *scene, int id) __attribute__((pure));
void Scene_DestroyEntity (scene_t *scene, struct entity_s *entity);
struct entity_s Scene_CreateEntity (scene_t *scene);
void Scene_DestroyEntity (scene_t *scene, struct entity_s entity);
void Scene_FreeAllEntities (scene_t *scene);

View file

@ -33,6 +33,7 @@
#include "QF/darray.h"
#include "QF/qtypes.h"
#include "QF/scene/component.h"
#include "QF/scene/hierarchy.h"
#include "QF/simd/vec4f.h"
#include "QF/simd/mat4f.h"
@ -59,50 +60,61 @@ enum {
};
typedef struct transform_s {
hierref_t ref;
ecs_registry_t *reg;
uint32_t id;
uint32_t comp;
} transform_t;
#define nulltransform ((transform_t) {})
#define XFORMINLINE GNU89INLINE inline __attribute__((pure))
transform_t *Transform_New (struct scene_s *scene, transform_t *parent);
XFORMINLINE int Transform_Valid (transform_t transform);
transform_t Transform_New (struct scene_s *scene, transform_t parent);
/* Deletes all child transforms, and transform names */
void Transform_Delete (struct scene_s *scene, transform_t *transform);
transform_t *Transform_NewNamed (struct scene_s *scene, transform_t *parent,
const char *name);
XFORMINLINE uint32_t Transform_ChildCount (const transform_t *transform);
XFORMINLINE transform_t *Transform_GetChild (const transform_t *transform,
uint32_t childIndex);
void Transform_Delete (struct scene_s *scene, transform_t transform);
transform_t Transform_NewNamed (struct scene_s *scene, transform_t parent,
const char *name);
XFORMINLINE hierref_t *Transform_GetRef (transform_t transform);
XFORMINLINE uint32_t Transform_ChildCount (transform_t transform);
XFORMINLINE transform_t Transform_GetChild (transform_t transform,
uint32_t childIndex);
void Transform_SetParent (struct scene_s *scene,
transform_t *transform, transform_t *parent);
XFORMINLINE transform_t *Transform_GetParent (const transform_t *transform);
void Transform_SetName (transform_t *transform, const char *name);
XFORMINLINE const char *Transform_GetName (const transform_t *transform);
void Transform_SetTag (transform_t *transform, uint32_t tag);
XFORMINLINE uint32_t Transform_GetTag (const transform_t *transform);
GNU89INLINE inline void Transform_GetLocalMatrix (const transform_t *transform, mat4f_t mat);
GNU89INLINE inline void Transform_GetLocalInverse (const transform_t *transform, mat4f_t mat);
GNU89INLINE inline void Transform_GetWorldMatrix (const transform_t *transform, mat4f_t mat);
transform_t transform, transform_t parent);
XFORMINLINE transform_t Transform_GetParent (transform_t transform);
void Transform_SetName (transform_t transform, const char *name);
XFORMINLINE const char *Transform_GetName (transform_t transform);
void Transform_SetTag (transform_t transform, uint32_t tag);
XFORMINLINE uint32_t Transform_GetTag (transform_t transform);
GNU89INLINE inline void Transform_GetLocalMatrix (transform_t transform,
mat4f_t mat);
GNU89INLINE inline void Transform_GetLocalInverse (transform_t transform,
mat4f_t mat);
GNU89INLINE inline void Transform_GetWorldMatrix (transform_t transform,
mat4f_t mat);
// XXX the pointer may be invalidated by hierarchy updates
XFORMINLINE const vec4f_t *Transform_GetWorldMatrixPtr (const transform_t *transform);
GNU89INLINE inline void Transform_GetWorldInverse (const transform_t *transform, mat4f_t mat);
XFORMINLINE vec4f_t Transform_GetLocalPosition (const transform_t *transform);
void Transform_SetLocalPosition (transform_t *transform, vec4f_t position);
XFORMINLINE vec4f_t Transform_GetLocalRotation (const transform_t *transform);
void Transform_SetLocalRotation (transform_t *transform, vec4f_t rotation);
XFORMINLINE vec4f_t Transform_GetLocalScale (const transform_t *transform);
void Transform_SetLocalScale (transform_t *transform, vec4f_t scale);
XFORMINLINE vec4f_t Transform_GetWorldPosition (const transform_t *transform);
void Transform_SetWorldPosition (transform_t *transform, vec4f_t position);
XFORMINLINE vec4f_t Transform_GetWorldRotation (const transform_t *transform);
void Transform_SetWorldRotation (transform_t *transform, vec4f_t rotation);
XFORMINLINE vec4f_t Transform_GetWorldScale (const transform_t *transform);
void Transform_SetLocalTransform (transform_t *transform, vec4f_t scale,
XFORMINLINE const vec4f_t *Transform_GetWorldMatrixPtr (transform_t transform);
GNU89INLINE inline void Transform_GetWorldInverse (transform_t transform,
mat4f_t mat);
XFORMINLINE vec4f_t Transform_GetLocalPosition (transform_t transform);
void Transform_SetLocalPosition (transform_t transform, vec4f_t position);
XFORMINLINE vec4f_t Transform_GetLocalRotation (transform_t transform);
void Transform_SetLocalRotation (transform_t transform, vec4f_t rotation);
XFORMINLINE vec4f_t Transform_GetLocalScale (transform_t transform);
void Transform_SetLocalScale (transform_t transform, vec4f_t scale);
XFORMINLINE vec4f_t Transform_GetWorldPosition (transform_t transform);
void Transform_SetWorldPosition (transform_t transform, vec4f_t position);
XFORMINLINE vec4f_t Transform_GetWorldRotation (transform_t transform);
void Transform_SetWorldRotation (transform_t transform, vec4f_t rotation);
XFORMINLINE vec4f_t Transform_GetWorldScale (transform_t transform);
void Transform_SetLocalTransform (transform_t transform, vec4f_t scale,
vec4f_t rotation, vec4f_t position);
// NOTE: these use X: forward, -Y: right, Z:up
// aslo, not guaranteed to be normalized or even orthogonal
XFORMINLINE vec4f_t Transform_Forward (const transform_t *transform);
XFORMINLINE vec4f_t Transform_Right (const transform_t *transform);
XFORMINLINE vec4f_t Transform_Up (const transform_t *transform);
XFORMINLINE vec4f_t Transform_Forward (transform_t transform);
XFORMINLINE vec4f_t Transform_Right (transform_t transform);
XFORMINLINE vec4f_t Transform_Up (transform_t transform);
// no SetWorldScale because after rotations, non uniform scale becomes shear
#undef XFORMINLINE
@ -113,43 +125,65 @@ XFORMINLINE vec4f_t Transform_Up (const transform_t *transform);
#endif
XFORMINLINE
uint32_t
Transform_ChildCount (const transform_t *transform)
int
Transform_Valid (transform_t transform)
{
__auto_type ref = (const hierref_t *) transform;
return transform.reg && ECS_EntValid (transform.id, transform.reg);
}
XFORMINLINE
hierref_t *
Transform_GetRef (transform_t transform)
{
return Ent_GetComponent (transform.id, transform.comp, transform.reg);
}
XFORMINLINE
uint32_t
Transform_ChildCount (transform_t transform)
{
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
return h->childCount[ref->index];
}
XFORMINLINE
transform_t *
Transform_GetChild (const transform_t *transform, uint32_t childIndex)
transform_t
Transform_GetChild (transform_t transform, uint32_t childIndex)
{
__auto_type ref = (const hierref_t *) transform;
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
if (childIndex >= h->childCount[ref->index]) {
return 0;
return nulltransform;
}
return (transform_t *) h->ref[h->childIndex[ref->index] + childIndex];
return (transform_t) {
.reg = transform.reg,
.id = h->ent[h->childIndex[ref->index] + childIndex],
.comp = transform.comp,
};
}
XFORMINLINE
transform_t *
Transform_GetParent (const transform_t *transform)
transform_t
Transform_GetParent (transform_t transform)
{
__auto_type ref = (const hierref_t *) transform;
__auto_type ref = Transform_GetRef (transform);
if (ref->index == 0) {
return 0;
return nulltransform;
}
hierarchy_t *h = ref->hierarchy;
return (transform_t *) h->ref[h->parentIndex[ref->index]];
return (transform_t) {
.reg = transform.reg,
.id = h->ent[h->parentIndex[ref->index]],
.comp = transform.comp,
};
}
XFORMINLINE
const char *
Transform_GetName (const transform_t *transform)
Transform_GetName (transform_t transform)
{
__auto_type ref = (const hierref_t *) transform;
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
char **name = h->components[transform_type_name];
return name[ref->index];
@ -157,9 +191,9 @@ Transform_GetName (const transform_t *transform)
XFORMINLINE
uint32_t
Transform_GetTag (const transform_t *transform)
Transform_GetTag (transform_t transform)
{
__auto_type ref = (const hierref_t *) transform;
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
uint32_t *tag = h->components[transform_type_tag];
return tag[ref->index];
@ -167,9 +201,9 @@ Transform_GetTag (const transform_t *transform)
XFORMINLINE
void
Transform_GetLocalMatrix (const transform_t *transform, mat4f_t mat)
Transform_GetLocalMatrix (transform_t transform, mat4f_t mat)
{
__auto_type ref = (const hierref_t *) transform;
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
mat4f_t *localMatrix = h->components[transform_type_localMatrix];
vec4f_t *src = localMatrix[ref->index];
@ -181,9 +215,9 @@ Transform_GetLocalMatrix (const transform_t *transform, mat4f_t mat)
XFORMINLINE
void
Transform_GetLocalInverse (const transform_t *transform, mat4f_t mat)
Transform_GetLocalInverse (transform_t transform, mat4f_t mat)
{
__auto_type ref = (const hierref_t *) transform;
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
mat4f_t *localInverse = h->components[transform_type_localInverse];
vec4f_t *src = localInverse[ref->index];
@ -195,9 +229,9 @@ Transform_GetLocalInverse (const transform_t *transform, mat4f_t mat)
XFORMINLINE
void
Transform_GetWorldMatrix (const transform_t *transform, mat4f_t mat)
Transform_GetWorldMatrix (transform_t transform, mat4f_t mat)
{
__auto_type ref = (const hierref_t *) transform;
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
mat4f_t *worldMatrix = h->components[transform_type_worldMatrix];
vec4f_t *src = worldMatrix[ref->index];
@ -209,9 +243,9 @@ Transform_GetWorldMatrix (const transform_t *transform, mat4f_t mat)
XFORMINLINE
const vec4f_t *
Transform_GetWorldMatrixPtr (const transform_t *transform)
Transform_GetWorldMatrixPtr (transform_t transform)
{
__auto_type ref = (const hierref_t *) transform;
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
mat4f_t *worldMatrix = h->components[transform_type_worldMatrix];
return worldMatrix[ref->index];
@ -219,9 +253,9 @@ Transform_GetWorldMatrixPtr (const transform_t *transform)
XFORMINLINE
void
Transform_GetWorldInverse (const transform_t *transform, mat4f_t mat)
Transform_GetWorldInverse (transform_t transform, mat4f_t mat)
{
__auto_type ref = (const hierref_t *) transform;
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
mat4f_t *worldInverse = h->components[transform_type_worldInverse];
vec4f_t *src = worldInverse[ref->index];
@ -233,9 +267,9 @@ Transform_GetWorldInverse (const transform_t *transform, mat4f_t mat)
XFORMINLINE
vec4f_t
Transform_GetLocalPosition (const transform_t *transform)
Transform_GetLocalPosition (transform_t transform)
{
__auto_type ref = (const hierref_t *) transform;
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
mat4f_t *localMatrix = h->components[transform_type_localMatrix];
return localMatrix[ref->index][3];
@ -243,9 +277,9 @@ Transform_GetLocalPosition (const transform_t *transform)
XFORMINLINE
vec4f_t
Transform_GetLocalRotation (const transform_t *transform)
Transform_GetLocalRotation (transform_t transform)
{
__auto_type ref = (const hierref_t *) transform;
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
vec4f_t *localRotation = h->components[transform_type_localRotation];
return localRotation[ref->index];
@ -253,9 +287,9 @@ Transform_GetLocalRotation (const transform_t *transform)
XFORMINLINE
vec4f_t
Transform_GetLocalScale (const transform_t *transform)
Transform_GetLocalScale (transform_t transform)
{
__auto_type ref = (const hierref_t *) transform;
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
vec4f_t *localScale = h->components[transform_type_localScale];
return localScale[ref->index];
@ -263,9 +297,9 @@ Transform_GetLocalScale (const transform_t *transform)
XFORMINLINE
vec4f_t
Transform_GetWorldPosition (const transform_t *transform)
Transform_GetWorldPosition (transform_t transform)
{
__auto_type ref = (const hierref_t *) transform;
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
mat4f_t *worldMatrix = h->components[transform_type_worldMatrix];
return worldMatrix[ref->index][3];
@ -273,9 +307,9 @@ Transform_GetWorldPosition (const transform_t *transform)
XFORMINLINE
vec4f_t
Transform_GetWorldRotation (const transform_t *transform)
Transform_GetWorldRotation (transform_t transform)
{
__auto_type ref = (const hierref_t *) transform;
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
vec4f_t *worldRotation = h->components[transform_type_worldRotation];
return worldRotation[ref->index];
@ -283,9 +317,9 @@ Transform_GetWorldRotation (const transform_t *transform)
XFORMINLINE
vec4f_t
Transform_GetWorldScale (const transform_t *transform)
Transform_GetWorldScale (transform_t transform)
{
__auto_type ref = (const hierref_t *) transform;
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
vec4f_t *worldScale = h->components[transform_type_worldScale];
return worldScale[ref->index];
@ -293,9 +327,9 @@ Transform_GetWorldScale (const transform_t *transform)
XFORMINLINE
vec4f_t
Transform_Forward (const transform_t *transform)
Transform_Forward (transform_t transform)
{
__auto_type ref = (const hierref_t *) transform;
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
mat4f_t *worldMatrix = h->components[transform_type_worldMatrix];
return worldMatrix[ref->index][0];
@ -303,9 +337,9 @@ Transform_Forward (const transform_t *transform)
XFORMINLINE
vec4f_t
Transform_Right (const transform_t *transform)
Transform_Right (transform_t transform)
{
__auto_type ref = (const hierref_t *) transform;
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
mat4f_t *worldMatrix = h->components[transform_type_worldMatrix];
return -worldMatrix[ref->index][1];
@ -313,9 +347,9 @@ Transform_Right (const transform_t *transform)
XFORMINLINE
vec4f_t
Transform_Up (const transform_t *transform)
Transform_Up (transform_t transform)
{
__auto_type ref = (const hierref_t *) transform;
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
mat4f_t *worldMatrix = h->components[transform_type_worldMatrix];
return worldMatrix[ref->index][2];

View file

@ -47,7 +47,6 @@ typedef struct uint32set_s DARRAY_TYPE (uint32_t) uint32set_t;
typedef struct byteset_s DARRAY_TYPE (byte) byteset_t;
typedef struct stringset_s DARRAY_TYPE (char *) stringset_t;
typedef struct xformset_s DARRAY_TYPE (struct transform_s *) xformset_t;
typedef struct entityset_s DARRAY_TYPE (struct entity_s *) entityset_t;
///@}

View file

@ -37,7 +37,7 @@ void SCR_Init (void);
typedef void (*SCR_Func)(void);
// scr_funcs is a null terminated array
void SCR_UpdateScreen (struct transform_s *camera, double realtime,
void SCR_UpdateScreen (struct transform_s camera, double realtime,
SCR_Func *scr_funcs);
void SCR_SetFOV (float fov);
// control whether the 3d viewport is user-controlled or always fullscreen

View file

@ -119,7 +119,7 @@ void S_StopAllSounds(void);
\param ambient_sound_level NUM_AMBIENTS bytes indicating current ambient
sound levels
*/
void S_Update (struct transform_s *ear, const byte *ambient_sound_level);
void S_Update (struct transform_s ear, const byte *ambient_sound_level);
/** Render some more sound without updating the client's position/orientation.
*/

View file

@ -37,9 +37,9 @@ struct entity_state_s;
void CL_NewDlight (int key, vec4f_t org, int effects, byte glow_size,
byte glow_color, double time);
void CL_ModelEffects (struct entity_s *ent, int num, int glow_color,
void CL_ModelEffects (struct entity_s ent, int num, int glow_color,
double time);
void CL_EntityEffects (int num, struct entity_s *ent,
void CL_EntityEffects (int num, struct entity_s ent,
struct entity_state_s *state, double time);
void CL_MuzzleFlash (vec4f_t position, vec4f_t fv, float zoffset, int num,
double time);

View file

@ -78,7 +78,7 @@ extern entstates_t qw_entstates;
extern vec3_t ent_colormod[256];
struct entity_s;
void CL_TransformEntity (struct entity_s *ent, float scale,
void CL_TransformEntity (struct entity_s ent, float scale,
const vec3_t angles, vec4f_t position);
#endif//__client_entities_h

View file

@ -52,7 +52,7 @@ typedef struct player_info_s {
struct info_key_s *skinname;
struct skin_s *skin;
struct entity_s *flag_ent;
entity_t flag_ent;
int spectator;
int stats[MAX_CL_STATS]; // health, etc

View file

@ -104,7 +104,7 @@ struct entity_s;
void CL_TEnts_Init (void);
void CL_TEnts_Precache (void);
void CL_Init_Entity (struct entity_s *ent);
void CL_Init_Entity (struct entity_s ent);
void CL_ClearTEnts (void);
void CL_UpdateTEnts (double time, TEntContext_t *ctx);
void CL_ParseTEnt_nq (struct msg_s *net_message, double time,

View file

@ -31,6 +31,7 @@
#include "QF/mathlib.h"
#include "QF/simd/types.h"
#include "QF/scene/entity.h"
typedef struct {
int destcolor[3];
@ -58,7 +59,7 @@ typedef struct viewstate_s {
vec4f_t velocity;
vec4f_t punchangle;
float frametime;
struct transform_s *camera_transform;
transform_t camera_transform;
double time;
float height;
int weaponframe;
@ -85,8 +86,8 @@ typedef struct viewstate_s {
double laststop;
struct model_s *weapon_model;
struct entity_s *weapon_entity;
struct entity_s *player_entity;
entity_t weapon_entity;
entity_t player_entity;
struct chasestate_s *chasestate;
} viewstate_t;

View file

@ -201,7 +201,7 @@ typedef struct
extern drawsurf_t r_drawsurf;
struct transform_s;
void R_DrawSurface (struct transform_s *transform);
void R_DrawSurface (struct transform_s transform);
void R_GenTile (msurface_t *psurf, void *pdest);
// !!! if this is changed, it must be changed in d_iface.h too !!!

View file

@ -92,7 +92,7 @@ void D_DrawSkyScans (struct espan_s *pspan);
void R_ShowSubDiv (void);
extern void (*prealspandrawer)(void);
struct entity_s;
surfcache_t *D_CacheSurface (struct entity_s *ent,
surfcache_t *D_CacheSurface (struct entity_s ent,
msurface_t *surface, int miplevel);
int D_MipLevelForScale (float scale) __attribute__((pure));

View file

@ -72,6 +72,7 @@ int R_InitGraphTextures (int base);
struct entity_s;
struct animation_s;
struct transform_s;
void R_DrawAliasModel (struct entity_s *e);
void R_MarkLeaves (struct mleaf_s *viewleaf, int *node_visframes,
@ -83,7 +84,7 @@ extern int *r_face_visframes;
void GL_SetPalette (void *data, const byte *palette);
void GLSL_SetPalette (void *data, const byte *palette);
int R_BillboardFrame (struct entity_s *ent, int orientation,
int R_BillboardFrame (struct transform_s transform, int orientation,
vec4f_t cameravec,
vec4f_t *bbup, vec4f_t *bbright, vec4f_t *bbfwd);
mspriteframe_t *R_GetSpriteFrame (const msprite_t *sprite,

View file

@ -145,33 +145,34 @@ void R_SetFrustum (plane_t *frustum, const union refframe_s *frame,
float fov_x, float fov_y);
struct entity_s;
struct animation_s;
void R_SpriteBegin (void);
void R_SpriteEnd (void);
void R_DrawSprite (struct entity_s *ent);
void R_RenderFace (struct entity_s *ent, msurface_t *fa, int clipflags);
void R_RenderPoly (struct entity_s *ent, msurface_t *fa, int clipflags);
void R_RenderBmodelFace (struct entity_s *ent, bedge_t *pedges, msurface_t *psurf);
void R_DrawSprite (struct entity_s ent);
void R_RenderFace (struct entity_s ent, msurface_t *fa, int clipflags);
void R_RenderPoly (struct entity_s ent, msurface_t *fa, int clipflags);
void R_RenderBmodelFace (struct entity_s ent, bedge_t *pedges, msurface_t *psurf);
void R_TransformFrustum (void);
void R_SetSkyFrame (void);
void R_DrawSurfaceBlock (void);
struct texture_s *R_TextureAnimation (const struct entity_s *entity, msurface_t *surf) __attribute__((pure));
struct texture_s *R_TextureAnimation (const struct animation_s *animation, msurface_t *surf) __attribute__((pure));
void R_GenSkyTile (void *pdest);
void R_SurfPatch (void);
void R_DrawSubmodelPolygons (struct entity_s *ent, model_t *pmodel, int clipflags, struct mleaf_s *topleaf);
void R_DrawSolidClippedSubmodelPolygons (struct entity_s *ent, model_t *pmodel, struct mnode_s *topnode);
void R_DrawSubmodelPolygons (struct entity_s ent, model_t *pmodel, int clipflags, struct mleaf_s *topleaf);
void R_DrawSolidClippedSubmodelPolygons (struct entity_s ent, model_t *pmodel, struct mnode_s *topnode);
void R_AddPolygonEdges (emitpoint_t *pverts, int numverts, int miplevel);
surf_t *R_GetSurf (void);
void R_AliasClipAndProjectFinalVert (finalvert_t *fv, auxvert_t *av);
void R_AliasDrawModel (struct entity_s *ent, alight_t *plighting);
void R_IQMDrawModel (struct entity_s *ent, alight_t *plighting);
void R_AliasDrawModel (struct entity_s ent, alight_t *plighting);
void R_IQMDrawModel (struct entity_s ent, alight_t *plighting);
struct animation_s;
maliasskindesc_t *R_AliasGetSkindesc (struct animation_s *animation, int skinnum, aliashdr_t *hdr);
maliasframedesc_t *R_AliasGetFramedesc (struct animation_s *animation, aliashdr_t *hdr);
float R_AliasGetLerpedFrames (struct animation_s *animation, aliashdr_t *hdr);
float R_IQMGetLerpedFrames (struct entity_s *ent, iqm_t *hdr);
float R_IQMGetLerpedFrames (struct animation_s *animation, iqm_t *hdr);
iqmframe_t *R_IQMBlendFrames (const iqm_t *iqm, int frame1, int frame2,
float blend, int extra);
iqmframe_t *R_IQMBlendPalette (const iqm_t *iqm, int frame1, int frame2,
@ -197,7 +198,7 @@ extern void R_EdgeCodeStart (void);
extern void R_EdgeCodeEnd (void);
struct transform_s;
extern void R_RotateBmodel (struct transform_s *transform);
extern void R_RotateBmodel (struct transform_s transform);
extern int c_faceclip;
extern int r_polycount;
@ -229,7 +230,7 @@ typedef struct btofpoly_s {
extern int numbtofpolys;
void R_InitTurb (void);
void R_ZDrawSubmodelPolys (struct entity_s *ent, model_t *clmodel);
void R_ZDrawSubmodelPolys (struct entity_s ent, model_t *clmodel);
// Alias models ===========================================
@ -244,7 +245,7 @@ extern auxvert_t *pauxverts;
extern float ziscale;
extern float aliastransform[3][4];
qboolean R_AliasCheckBBox (struct entity_s *ent);
qboolean R_AliasCheckBBox (struct entity_s ent);
// turbulence stuff =======================================

View file

@ -99,7 +99,7 @@ typedef struct surf_s {
// start)
int flags; // currentface flags
void *data; // associated data like msurface_t
struct entity_s *entity;
entity_t entity;
float nearzi; // nearest 1/z on surface, for mipmapping
qboolean insubmodel;
float d_ziorigin, d_zistepu, d_zistepv;

View file

@ -8,11 +8,7 @@
#include "QF/scene/transform.h"
typedef struct scene_resources_s {
PR_RESMAP (entity_t) entities;
PR_RESMAP (hierarchy_t) hierarchies;
PR_RESMAP (hierref_t) transforms;
} scene_resources_t;
hierref_t *__transform_alloc (struct scene_s *scene);
#endif//__scn_internal_h

View file

@ -396,7 +396,7 @@ void SND_SetAmbient (snd_t *snd, int amb_channel, sfx_t *sfx);
\param ambient_sound_level Pointer to 4 bytes indicating the levels at
which to play the ambient sounds.
*/
void SND_SetListener (snd_t *snd, struct transform_s *ear,
void SND_SetListener (snd_t *snd, struct transform_s ear,
const byte *ambient_sound_level);
/** Stop all sounds from playing.

View file

@ -578,9 +578,9 @@ s_combine_channel (channel_t *combine, channel_t *ch)
}
void
SND_SetListener (snd_t *snd, transform_t *ear, const byte *ambient_sound_level)
SND_SetListener (snd_t *snd, transform_t ear, const byte *ambient_sound_level)
{
if (ear) {
if (Transform_Valid (ear)) {
listener_origin = Transform_GetWorldPosition (ear);
listener_forward = Transform_Forward (ear);
listener_right = Transform_Right (ear);

View file

@ -50,6 +50,8 @@
#include "QF/va.h"
#include "QF/quakefs.h"
#include "QF/scene/transform.h"
#include "snd_internal.h"
static int snd_blocked = 0;
@ -252,7 +254,7 @@ s_update_ (void)
Called once each time through the main loop
*/
static void
s_update (struct transform_s *ear, const byte *ambient_sound_level)
s_update (transform_t ear, const byte *ambient_sound_level)
{
if (!sound_started || (snd_blocked > 0))
return;

View file

@ -35,6 +35,8 @@
#include "QF/qargs.h"
#include "QF/sys.h"
#include "QF/scene/transform.h"
#include "snd_internal.h"
static char *snd_output;
@ -187,7 +189,7 @@ S_PrecacheSound (const char *sample)
}
VISIBLE void
S_Update (struct transform_s *ear, const byte *ambient_sound_level)
S_Update (transform_t ear, const byte *ambient_sound_level)
{
if (snd_render_funcs)
snd_render_funcs->update (ear, ambient_sound_level);

View file

@ -46,6 +46,7 @@
#include "QF/zone.h"
#include "QF/sound.h"
#include "QF/scene/transform.h"
#ifdef _WIN32
# include "winquake.h"
@ -88,7 +89,7 @@ main (int argc, const char *argv[])
while (1) {
Cbuf_Execute_Stack (testsound_cbuf);
S_Update (0, 0);
S_Update (nulltransform, 0);
usleep(20 * 1000);
}
Sys_Quit ();

View file

@ -41,11 +41,14 @@
#include "QF/render.h"
#include "QF/plugin/vid_render.h" //FIXME
#include "QF/scene/component.h"
#include "QF/scene/entity.h"
#include "QF/scene/scene.h"
#include "client/entities.h"
#include "client/effects.h"
#include "client/particles.h"
#include "client/world.h"
void
CL_NewDlight (int key, vec4f_t org, int effects, byte glow_size,
@ -115,12 +118,14 @@ CL_NewDlight (int key, vec4f_t org, int effects, byte glow_size,
}
void
CL_ModelEffects (entity_t *ent, int num, int glow_color, double time)
CL_ModelEffects (entity_t ent, int num, int glow_color, double time)
{
dlight_t *dl;
model_t *model = ent->renderer.model;
vec4f_t old_origin = ent->old_origin;
vec4f_t ent_origin = Transform_GetWorldPosition (ent->transform);
transform_t transform = Entity_Transform (ent);
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, cl_world.scene->reg);
model_t *model = renderer->model;
vec4f_t *old_origin = Ent_GetComponent (ent.id, scene_old_origin, cl_world.scene->reg);
vec4f_t ent_origin = Transform_GetWorldPosition (transform);
// add automatic particle trails
if (model->flags & EF_ROCKET) {
@ -133,21 +138,21 @@ CL_ModelEffects (entity_t *ent, int num, int glow_color, double time)
VectorSet (0.9, 0.7, 0.0, dl->color);
dl->color[3] = 0.7;
}
clp_funcs->RocketTrail (old_origin, ent_origin);
clp_funcs->RocketTrail (*old_origin, ent_origin);
} else if (model->flags & EF_GRENADE)
clp_funcs->GrenadeTrail (old_origin, ent_origin);
clp_funcs->GrenadeTrail (*old_origin, ent_origin);
else if (model->flags & EF_GIB)
clp_funcs->BloodTrail (old_origin, ent_origin);
clp_funcs->BloodTrail (*old_origin, ent_origin);
else if (model->flags & EF_ZOMGIB)
clp_funcs->SlightBloodTrail (old_origin, ent_origin);
clp_funcs->SlightBloodTrail (*old_origin, ent_origin);
else if (model->flags & EF_TRACER)
clp_funcs->WizTrail (old_origin, ent_origin);
clp_funcs->WizTrail (*old_origin, ent_origin);
else if (model->flags & EF_TRACER2)
clp_funcs->FlameTrail (old_origin, ent_origin);
clp_funcs->FlameTrail (*old_origin, ent_origin);
else if (model->flags & EF_TRACER3)
clp_funcs->VoorTrail (old_origin, ent_origin);
clp_funcs->VoorTrail (*old_origin, ent_origin);
else if (model->flags & EF_GLOWTRAIL)
clp_funcs->GlowTrail (old_origin, ent_origin, glow_color);
clp_funcs->GlowTrail (*old_origin, ent_origin, glow_color);
}
void
@ -170,13 +175,14 @@ CL_MuzzleFlash (vec4f_t position, vec4f_t fv, float zoffset, int num,
}
void
CL_EntityEffects (int num, entity_t *ent, entity_state_t *state, double time)
CL_EntityEffects (int num, entity_t ent, entity_state_t *state, double time)
{
vec4f_t position = Transform_GetWorldPosition (ent->transform);
transform_t transform = Entity_Transform (ent);
vec4f_t position = Transform_GetWorldPosition (transform);
if (state->effects & EF_BRIGHTFIELD)
clp_funcs->EntityParticles (position);
if (state->effects & EF_MUZZLEFLASH) {
vec4f_t fv = Transform_Forward (ent->transform);
vec4f_t fv = Transform_Forward (transform);
CL_MuzzleFlash (position, fv, 16, num, time);
}
}

View file

@ -39,8 +39,13 @@
#include "QF/plugin/vid_render.h" //FIXME
#include "QF/scene/component.h"
#include "QF/scene/entity.h"
#include "QF/scene/scene.h"
#include "client/entities.h"
#include "client/temp_entities.h"
#include "client/world.h"
entitystateset_t cl_static_entities = DARRAY_STATIC_INIT (32);
@ -353,7 +358,7 @@ vec3_t ent_colormod[256] = {
};
void
CL_TransformEntity (entity_t *ent, float scale, const vec3_t angles,
CL_TransformEntity (entity_t ent, float scale, const vec3_t angles,
vec4f_t position)
{
vec4f_t rotation;
@ -364,7 +369,9 @@ CL_TransformEntity (entity_t *ent, float scale, const vec3_t angles,
} else {
vec3_t ang;
VectorCopy (angles, ang);
if (ent->renderer.model && ent->renderer.model->type == mod_alias) {
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer,
ent.reg);
if (renderer->model && renderer->model->type == mod_alias) {
// stupid quake bug
// why, oh, why, do alias models pitch in the opposite direction
// to everything else?
@ -372,5 +379,6 @@ CL_TransformEntity (entity_t *ent, float scale, const vec3_t angles,
}
AngleQuat (ang, (vec_t*)&rotation);//FIXME
}
Transform_SetLocalTransform (ent->transform, scalevec, rotation, position);
transform_t transform = Entity_Transform (ent);
Transform_SetLocalTransform (transform, scalevec, rotation, position);
}

View file

@ -45,6 +45,8 @@
#include "QF/sound.h"
#include "QF/plugin/vid_render.h" //FIXME
//
#include "QF/scene/component.h"
#include "QF/scene/entity.h"
#include "QF/scene/scene.h"
@ -56,7 +58,7 @@
typedef struct tent_s {
struct tent_s *next;
entity_t *ent;
entity_t ent;
} tent_t;
typedef struct {
@ -153,17 +155,22 @@ CL_TEnts_Init (void)
}
void
CL_Init_Entity (entity_t *ent)
CL_Init_Entity (entity_t ent)
{
memset (&ent->animation, 0, sizeof (ent->animation));
memset (&ent->visibility, 0, sizeof (ent->visibility));
memset (&ent->renderer, 0, sizeof (ent->renderer));
ent->active = 1;
ent->old_origin = (vec4f_t) {};
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, cl_world.scene->reg);
visibility_t *visibility = Ent_GetComponent (ent.id, scene_visibility, cl_world.scene->reg);
animation_t *animation = Ent_GetComponent (ent.id, scene_animation, cl_world.scene->reg);
byte *active = Ent_GetComponent (ent.id, scene_active, cl_world.scene->reg);
vec4f_t *old_origin = Ent_GetComponent (ent.id, scene_old_origin, cl_world.scene->reg);
memset (animation, 0, sizeof (*animation));
memset (visibility, 0, sizeof (*visibility));
memset (renderer, 0, sizeof (*renderer));
*active = 1;
*old_origin = (vec4f_t) {0, 0, 0, 1};
ent->renderer.skin = 0;
QuatSet (1.0, 1.0, 1.0, 1.0, ent->renderer.colormod);
ent->animation.pose1 = ent->animation.pose2 = -1;
renderer->skin = 0;
QuatSet (1.0, 1.0, 1.0, 1.0, renderer->colormod);
animation->pose1 = animation->pose2 = -1;
}
static tent_t *
@ -221,7 +228,6 @@ beam_clear (beam_t *b)
for (t = b->tents; t; t = t->next) {
R_RemoveEfrags (t->ent);
t->ent->visibility.efrag = 0;
}
free_temp_entities (b->tents);
b->tents = 0;
@ -229,7 +235,7 @@ beam_clear (beam_t *b)
}
static inline void
beam_setup (beam_t *b, qboolean transform, double time, TEntContext_t *ctx)
beam_setup (beam_t *b, qboolean settransform, double time, TEntContext_t *ctx)
{
tent_t *tent;
float d;
@ -268,15 +274,17 @@ beam_setup (beam_t *b, qboolean transform, double time, TEntContext_t *ctx)
vec4f_t position = org + d * dist;
d += 1.0;
tent->ent->renderer.model = b->model;
if (transform) {
transform_t transform = Entity_Transform (tent->ent);
renderer_t *renderer = Ent_GetComponent (tent->ent.id, scene_renderer, cl_world.scene->reg);
renderer->model = b->model;
if (settransform) {
seed = seed * BEAM_SEED_PRIME;
Transform_SetLocalTransform (tent->ent->transform, scale,
Transform_SetLocalTransform (transform, scale,
qmulf (rotation,
beam_rolls[seed % 360]),
position);
} else {
Transform_SetLocalPosition (tent->ent->transform, position);
Transform_SetLocalPosition (transform, position);
}
R_AddEfrags (&cl_world.scene->worldmodel->brush, tent->ent);
}
@ -382,9 +390,10 @@ parse_tent (qmsg_t *net_message, double time, TEntContext_t *ctx,
if (!cl_spr_explod->cache.data) {
cl_spr_explod = Mod_ForName ("progs/s_explod.spr", true);
}
ex->tent->ent->renderer.model = cl_spr_explod;
Transform_SetLocalPosition (ex->tent->ent->transform,//FIXME
(vec4f_t) {VectorExpand (position), 1});
transform_t transform = Entity_Transform (ex->tent->ent);
renderer_t *renderer = Ent_GetComponent (ex->tent->ent.id, scene_renderer, cl_world.scene->reg);
renderer->model = cl_spr_explod;
Transform_SetLocalPosition (transform, position);
break;
case TE_Explosion2:
MSG_ReadCoordV (net_message, (vec_t*)&position);//FIXME
@ -606,7 +615,8 @@ CL_UpdateBeams (double time, TEntContext_t *ctx)
// add new entities for the lightning
for (t = b->tents; t; t = t->next) {
seed = seed * BEAM_SEED_PRIME;
Transform_SetLocalRotation (t->ent->transform,
transform_t transform = Entity_Transform (t->ent);
Transform_SetLocalRotation (transform,
qmulf (b->rotation,
beam_rolls[seed % 360]));
}
@ -619,16 +629,18 @@ CL_UpdateExplosions (double time, TEntContext_t *ctx)
int f;
tent_obj_t **to;
explosion_t *ex;
entity_t *ent;
entity_t ent;
for (to = &cl_explosions; *to; ) {
ex = &(*to)->to.ex;
ent = ex->tent->ent;
f = 10 * (time - ex->start);
if (f >= ent->renderer.model->numframes) {
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, cl_world.scene->reg);
visibility_t *visibility = Ent_GetComponent (ent.id, scene_visibility, cl_world.scene->reg);
animation_t *animation = Ent_GetComponent (ent.id, scene_animation, cl_world.scene->reg);
if (f >= renderer->model->numframes) {
tent_obj_t *_to;
R_RemoveEfrags (ent);
ent->visibility.efrag = 0;
free_temp_entities (ex->tent);
_to = *to;
*to = _to->next;
@ -637,8 +649,8 @@ CL_UpdateExplosions (double time, TEntContext_t *ctx)
}
to = &(*to)->next;
ent->animation.frame = f;
if (!ent->visibility.efrag) {
animation->frame = f;
if (!visibility->efrag) {
R_AddEfrags (&cl_world.scene->worldmodel->brush, ent);
}
}
@ -681,7 +693,6 @@ CL_ClearProjectiles (void)
for (tent = cl_projectiles; tent; tent = tent->next) {
R_RemoveEfrags (tent->ent);
tent->ent->visibility.efrag = 0;
}
free_temp_entities (cl_projectiles);
cl_projectiles = 0;
@ -697,7 +708,7 @@ CL_ParseProjectiles (qmsg_t *net_message, qboolean nail2, TEntContext_t *ctx)
tent_t *head = 0, **tail = &head;
byte bits[6];
int i, c, j, num;
entity_t *pr;
entity_t pr;
vec4f_t position = { 0, 0, 0, 1 };
vec3_t angles;
@ -718,8 +729,9 @@ CL_ParseProjectiles (qmsg_t *net_message, qboolean nail2, TEntContext_t *ctx)
tail = &tent->next;
pr = tent->ent;
pr->renderer.model = cl_spike;
pr->renderer.skin = 0;
renderer_t *renderer = Ent_GetComponent (pr.id, scene_renderer, cl_world.scene->reg);
renderer->model = cl_spike;
renderer->skin = 0;
position[0] = ((bits[0] + ((bits[1] & 15) << 8)) << 1) - 4096;
position[1] = (((bits[1] >> 4) + (bits[2] << 4)) << 1) - 4096;
position[2] = ((bits[3] + ((bits[4] & 15) << 8)) << 1) - 4096;
@ -728,7 +740,7 @@ CL_ParseProjectiles (qmsg_t *net_message, qboolean nail2, TEntContext_t *ctx)
angles[2] = 0;
CL_TransformEntity (tent->ent, 1, angles, position);
R_AddEfrags (&cl_world.scene->worldmodel->brush, tent->ent);
R_AddEfrags (&cl_world.scene->worldmodel->brush, pr);
}
*tail = cl_projectiles;

View file

@ -34,8 +34,9 @@
#include "QF/screen.h"
#include "QF/plugin/vid_render.h"
#include "QF/scene/component.h"
#include "QF/scene/entity.h"
#include "QF/scene/transform.h"
#include "QF/scene/scene.h"
#include "QF/simd/vec4f.h"
#include "compat.h"
@ -672,7 +673,8 @@ CalcGunAngle (viewstate_t *vs)
{
vec4f_t rotation = Transform_GetWorldRotation (vs->camera_transform);
//FIXME make child of camera
Transform_SetWorldRotation (vs->weapon_entity->transform, rotation);
transform_t wep_form = Entity_Transform (vs->weapon_entity);
Transform_SetWorldRotation (wep_form, rotation);
}
static void
@ -726,9 +728,9 @@ V_AddIdle (viewstate_t *vs)
Transform_SetWorldRotation (vs->camera_transform, qmulf (rot, rotation));
// counter-rotate the weapon
rot = qmulf (qconjf (rot),
Transform_GetWorldRotation (vs->weapon_entity->transform));
Transform_SetWorldRotation (vs->weapon_entity->transform, rot);
transform_t wep_form = Entity_Transform (vs->weapon_entity);
rot = qmulf (qconjf (rot), Transform_GetWorldRotation (wep_form));
Transform_SetWorldRotation (wep_form, rot);
}
/*
@ -765,18 +767,20 @@ static void
V_CalcIntermissionRefdef (viewstate_t *vs)
{
// vs->player_entity is the player model (visible when out of body)
entity_t *ent = vs->player_entity;
entity_t *view;
entity_t ent = vs->player_entity;
entity_t view;
float old;
vec4f_t origin = Transform_GetWorldPosition (ent->transform);
vec4f_t rotation = Transform_GetWorldRotation (ent->transform);
transform_t transform = Entity_Transform (ent);
vec4f_t origin = Transform_GetWorldPosition (transform);
vec4f_t rotation = Transform_GetWorldRotation (transform);
// view is the weapon model (visible only from inside body)
view = vs->weapon_entity;
Transform_SetWorldPosition (vs->camera_transform, origin);
Transform_SetWorldRotation (vs->camera_transform, rotation);
view->renderer.model = NULL;
renderer_t *renderer = Ent_GetComponent (view.id, scene_renderer, cl_world.scene->reg);
renderer->model = NULL;
// always idle in intermission
old = v_idlescale;
@ -789,13 +793,16 @@ static void
V_CalcRefdef (viewstate_t *vs)
{
// view is the weapon model (visible only from inside body)
entity_t *view = vs->weapon_entity;
entity_t view = vs->weapon_entity;
float bob;
static float oldz = 0;
vec4f_t forward = {}, right = {}, up = {};
vec4f_t origin = vs->player_origin;
vec_t *viewangles = vs->player_angles;
renderer_t *renderer = Ent_GetComponent (view.id, scene_renderer, cl_world.scene->reg);
animation_t *animation = Ent_GetComponent (view.id, scene_animation, cl_world.scene->reg);
V_DriftPitch (vs);
bob = V_CalcBob (vs);
@ -851,12 +858,12 @@ V_CalcRefdef (viewstate_t *vs)
if (vs->flags & (VF_GIB | VF_DEAD)) {
model = NULL;
}
if (view->renderer.model != model) {
view->animation.pose2 = -1;
if (renderer->model != model) {
animation->pose2 = -1;
}
view->renderer.model = model;
view->animation.frame = vs->weaponframe;
view->renderer.skin = 0;
renderer->model = model;
animation->frame = vs->weaponframe;
renderer->skin = 0;
// set up the refresh position
Transform_SetWorldRotation (vs->camera_transform,
@ -954,7 +961,7 @@ V_Init (viewstate_t *viewstate)
"Used when you are underwater, hit, have the Ring of "
"Shadows, or Quad Damage. (v_cshift r g b intensity)");
viewstate->camera_transform = Transform_New (cl_world.scene, 0);
viewstate->camera_transform = Transform_New (cl_world.scene, nulltransform);
}
void

View file

@ -46,6 +46,7 @@
#include "QF/progs.h"
#include "QF/msg.h"
#include "QF/scene/component.h"
#include "QF/scene/entity.h"
#include "QF/scene/light.h"
#include "QF/scene/scene.h"
@ -105,7 +106,7 @@ CL_ParseBaseline (qmsg_t *msg, entity_state_t *baseline, int version)
void
CL_ParseStatic (qmsg_t *msg, int version)
{
entity_t *ent;
entity_t ent;
entity_state_t es;
ent = Scene_CreateEntity (cl_world.scene);
@ -114,10 +115,13 @@ CL_ParseStatic (qmsg_t *msg, int version)
CL_ParseBaseline (msg, &es, version);
DARRAY_APPEND (&cl_static_entities, es);
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, cl_world.scene->reg);
animation_t *animation = Ent_GetComponent (ent.id, scene_animation, cl_world.scene->reg);
// copy it to the current state
ent->renderer.model = cl_world.models.a[es.modelindex];
ent->animation.frame = es.frame;
ent->renderer.skinnum = es.skinnum;
renderer->model = cl_world.models.a[es.modelindex];
animation->frame = es.frame;
renderer->skinnum = es.skinnum;
CL_TransformEntity (ent, es.scale / 16.0, es.angles, es.origin);

View file

@ -44,6 +44,7 @@
#include "QF/plugin/vid_render.h"
#include "QF/scene/component.h"
#include "QF/scene/entity.h"
#include "QF/scene/light.h"
#include "QF/scene/scene.h"
@ -110,38 +111,38 @@ rua_scene_index (rua_scene_resources_t *res, rua_scene_t *scene)
return PR_RESINDEX (res->scene_map, scene);
}
static entity_t * __attribute__((pure))
static entity_t __attribute__((pure))
rua__entity_get (rua_scene_resources_t *res, pr_ulong_t id, const char *name)
{
pr_ulong_t scene_id = id & 0xffffffff;
entity_t *ent = 0;
entity_t ent = nullentity;
rua_scene_t *scene = rua__scene_get (res, scene_id, name);
if (scene) {
pr_int_t entity_id = id >> 32;
ent = Scene_GetEntity (scene->scene, entity_id);
ent.id = entity_id;
}
if (!ent) {
if (!Entity_Valid (ent)) {
PR_RunError (res->pr, "invalid entity passed to %s", name + 3);
}
return ent;
}
#define rua_entity_get(res, id) rua__entity_get(res, id, __FUNCTION__)
static transform_t * __attribute__((pure))
static transform_t __attribute__((pure))
rua__transform_get (rua_scene_resources_t *res, pr_ulong_t id, const char *name)
{
pr_ulong_t scene_id = id & 0xffffffff;
transform_t *transform = 0;
transform_t transform = nulltransform;
rua_scene_t *scene = rua_scene_get (res, scene_id);
if (scene) {
pr_int_t transform_id = id >> 32;
transform = Scene_GetTransform (scene->scene, transform_id);
entity_t transform_id = { .reg = scene->scene->reg, .id = id >> 32 };
transform = Entity_Transform (transform_id);
}
if (!transform) {
if (!Transform_Valid (transform)) {
PR_RunError (res->pr, "invalid transform passed to %s", name + 3);
}
return transform;
@ -245,8 +246,8 @@ bi_Scene_CreateEntity (progs_t *pr, void *_res)
rua_scene_resources_t *res = _res;
pr_ulong_t scene_id = P_ULONG (pr, 0);
rua_scene_t *scene = rua_scene_get (res, scene_id);
entity_t *ent = Scene_CreateEntity (scene->scene);
R_ULONG (pr) = MAKE_ID (ent->id, scene_id);
entity_t ent = Scene_CreateEntity (scene->scene);
R_ULONG (pr) = MAKE_ID (ent.id, scene_id);
}
static void
@ -254,12 +255,12 @@ bi_Scene_DestroyEntity (progs_t *pr, void *_res)
{
rua_scene_resources_t *res = _res;
pr_ulong_t id = P_ULONG (pr, 0);
entity_t *ent = rua_entity_get (res, id);
entity_t ent = rua_entity_get (res, id);
pr_ulong_t scene_id = id & 0xffffffff;
rua_scene_t *scene = rua_scene_get (res, scene_id);
R_RemoveEfrags (ent);
// bad scene caught above
rua_scene_t *scene = rua_scene_get (res, scene_id);
Scene_DestroyEntity (scene->scene, ent);
}
@ -282,12 +283,10 @@ bi_Scene_SetLighting (progs_t *pr, void *_res)
static void
bi_Entity_GetTransform (progs_t *pr, void *_res)
{
rua_scene_resources_t *res = _res;
pr_ulong_t ent_id = P_ULONG (pr, 0);
entity_t *ent = rua_entity_get (res, ent_id);
// ent_id contains scene id
R_ULONG (pr) = MAKE_ID (ent->transform->ref.id, ent_id);
// ent_id is used to fetch the transform every time
R_ULONG (pr) = ent_id;
}
static void
@ -296,14 +295,15 @@ bi_Entity_SetModel (progs_t *pr, void *_res)
rua_scene_resources_t *res = _res;
pr_ulong_t ent_id = P_ULONG (pr, 0);
pr_int_t model_id = P_INT (pr, 1);
entity_t *ent = rua_entity_get (res, ent_id);
entity_t ent = rua_entity_get (res, ent_id);
model_t *model = Model_GetModel (pr, model_id);
pr_ulong_t scene_id = ent_id & 0xffffffff;
// bad scene caught above
rua_scene_t *scene = rua_scene_get (res, scene_id);
R_RemoveEfrags (ent);
ent->renderer.model = model;
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, scene->scene->reg);
renderer->model = model;
R_AddEfrags (&scene->scene->worldmodel->brush, ent);
}
@ -311,7 +311,7 @@ static void
bi_Transform_ChildCount (progs_t *pr, void *_res)
{
rua_scene_resources_t *res = _res;
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
transform_t transform = rua_transform_get (res, P_ULONG (pr, 0));
R_UINT (pr) = Transform_ChildCount (transform);
}
@ -320,18 +320,19 @@ static void
bi_Transform_GetChild (progs_t *pr, void *_res)
{
rua_scene_resources_t *res = _res;
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
transform_t *child = Transform_GetChild (transform, P_UINT (pr, 2));
R_UINT (pr) = child ? child->ref.id : 0;
pr_ulong_t transform_id = P_ULONG (pr, 0);
transform_t transform = rua_transform_get (res, transform_id);
transform_t child = Transform_GetChild (transform, P_UINT (pr, 2));
R_ULONG (pr) = Transform_Valid (child) ? MAKE_ID (child.id, transform_id)
: 0;
}
static void
bi_Transform_SetParent (progs_t *pr, void *_res)
{
rua_scene_resources_t *res = _res;
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
transform_t *parent = rua_transform_get (res, P_ULONG (pr, 1));
transform_t transform = rua_transform_get (res, P_ULONG (pr, 0));
transform_t parent = rua_transform_get (res, P_ULONG (pr, 1));
rua_scene_t *scene = rua_scene_get (res, P_ULONG (pr, 1));
Transform_SetParent (scene->scene, transform, parent);
@ -342,18 +343,19 @@ bi_Transform_GetParent (progs_t *pr, void *_res)
{
rua_scene_resources_t *res = _res;
pr_ulong_t transform_id = P_ULONG (pr, 0);
transform_t *transform = rua_transform_get (res, transform_id);
transform_t *parent = Transform_GetParent (transform);
transform_t transform = rua_transform_get (res, transform_id);
transform_t parent = Transform_GetParent (transform);
// transform_id contains scene id
R_ULONG (pr) = parent ? MAKE_ID (parent->ref.id, transform_id) : 0;
R_ULONG (pr) = Transform_Valid (parent) ? MAKE_ID (parent.id, transform_id)
: 0;
}
static void
bi_Transform_SetTag (progs_t *pr, void *_res)
{
rua_scene_resources_t *res = _res;
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
transform_t transform = rua_transform_get (res, P_ULONG (pr, 0));
pr_uint_t tag = P_UINT (pr, 2);
Transform_SetTag (transform, tag);
}
@ -362,7 +364,7 @@ static void
bi_Transform_GetTag (progs_t *pr, void *_res)
{
rua_scene_resources_t *res = _res;
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
transform_t transform = rua_transform_get (res, P_ULONG (pr, 0));
R_UINT (pr) = Transform_GetTag (transform);
}
@ -371,7 +373,7 @@ static void
bi_Transform_GetLocalMatrix (progs_t *pr, void *_res)
{
rua_scene_resources_t *res = _res;
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
transform_t transform = rua_transform_get (res, P_ULONG (pr, 0));
Transform_GetLocalMatrix (transform, &R_PACKED (pr, pr_vec4_t));
}
@ -379,7 +381,7 @@ static void
bi_Transform_GetLocalInverse (progs_t *pr, void *_res)
{
rua_scene_resources_t *res = _res;
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
transform_t transform = rua_transform_get (res, P_ULONG (pr, 0));
Transform_GetLocalInverse (transform, &R_PACKED (pr, pr_vec4_t));
}
@ -387,7 +389,7 @@ static void
bi_Transform_GetWorldMatrix (progs_t *pr, void *_res)
{
rua_scene_resources_t *res = _res;
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
transform_t transform = rua_transform_get (res, P_ULONG (pr, 0));
Transform_GetWorldMatrix (transform, &R_PACKED (pr, pr_vec4_t));
}
@ -395,7 +397,7 @@ static void
bi_Transform_GetWorldInverse (progs_t *pr, void *_res)
{
rua_scene_resources_t *res = _res;
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
transform_t transform = rua_transform_get (res, P_ULONG (pr, 0));
Transform_GetWorldInverse (transform, &R_PACKED (pr, pr_vec4_t));
}
@ -403,7 +405,7 @@ static void
bi_Transform_SetLocalPosition (progs_t *pr, void *_res)
{
rua_scene_resources_t *res = _res;
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
transform_t transform = rua_transform_get (res, P_ULONG (pr, 0));
Transform_SetLocalPosition (transform, P_PACKED (pr, pr_vec4_t, 1));
}
@ -411,7 +413,7 @@ static void
bi_Transform_GetLocalPosition (progs_t *pr, void *_res)
{
rua_scene_resources_t *res = _res;
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
transform_t transform = rua_transform_get (res, P_ULONG (pr, 0));
R_PACKED (pr, pr_vec4_t) = Transform_GetLocalPosition (transform);
}
@ -419,7 +421,7 @@ static void
bi_Transform_SetLocalRotation (progs_t *pr, void *_res)
{
rua_scene_resources_t *res = _res;
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
transform_t transform = rua_transform_get (res, P_ULONG (pr, 0));
Transform_SetLocalRotation (transform, P_PACKED (pr, pr_vec4_t, 1));
}
@ -427,7 +429,7 @@ static void
bi_Transform_GetLocalRotation (progs_t *pr, void *_res)
{
rua_scene_resources_t *res = _res;
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
transform_t transform = rua_transform_get (res, P_ULONG (pr, 0));
R_PACKED (pr, pr_vec4_t) = Transform_GetLocalRotation (transform);
}
@ -435,7 +437,7 @@ static void
bi_Transform_SetLocalScale (progs_t *pr, void *_res)
{
rua_scene_resources_t *res = _res;
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
transform_t transform = rua_transform_get (res, P_ULONG (pr, 0));
Transform_SetLocalScale (transform, P_PACKED (pr, pr_vec4_t, 1));
}
@ -443,7 +445,7 @@ static void
bi_Transform_GetLocalScale (progs_t *pr, void *_res)
{
rua_scene_resources_t *res = _res;
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
transform_t transform = rua_transform_get (res, P_ULONG (pr, 0));
R_PACKED (pr, pr_vec4_t) = Transform_GetLocalScale (transform);
}
@ -451,7 +453,7 @@ static void
bi_Transform_SetWorldPosition (progs_t *pr, void *_res)
{
rua_scene_resources_t *res = _res;
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
transform_t transform = rua_transform_get (res, P_ULONG (pr, 0));
Transform_SetWorldPosition (transform, P_PACKED (pr, pr_vec4_t, 1));
}
@ -459,7 +461,7 @@ static void
bi_Transform_GetWorldPosition (progs_t *pr, void *_res)
{
rua_scene_resources_t *res = _res;
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
transform_t transform = rua_transform_get (res, P_ULONG (pr, 0));
R_PACKED (pr, pr_vec4_t) = Transform_GetWorldPosition (transform);
}
@ -467,7 +469,7 @@ static void
bi_Transform_SetWorldRotation (progs_t *pr, void *_res)
{
rua_scene_resources_t *res = _res;
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
transform_t transform = rua_transform_get (res, P_ULONG (pr, 0));
Transform_SetWorldRotation (transform, P_PACKED (pr, pr_vec4_t, 1));
}
@ -475,7 +477,7 @@ static void
bi_Transform_GetWorldRotation (progs_t *pr, void *_res)
{
rua_scene_resources_t *res = _res;
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
transform_t transform = rua_transform_get (res, P_ULONG (pr, 0));
R_PACKED (pr, pr_vec4_t) = Transform_GetWorldRotation (transform);
}
@ -483,7 +485,7 @@ static void
bi_Transform_GetWorldScale (progs_t *pr, void *_res)
{
rua_scene_resources_t *res = _res;
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
transform_t transform = rua_transform_get (res, P_ULONG (pr, 0));
R_PACKED (pr, pr_vec4_t) = Transform_GetWorldScale (transform);
}
@ -491,7 +493,7 @@ static void
bi_Transform_SetLocalTransform (progs_t *pr, void *_res)
{
rua_scene_resources_t *res = _res;
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
transform_t transform = rua_transform_get (res, P_ULONG (pr, 0));
Transform_SetLocalTransform (transform, P_PACKED (pr, pr_vec4_t, 1),
P_PACKED (pr, pr_vec4_t, 2), P_PACKED (pr, pr_vec4_t, 3));
}
@ -500,7 +502,7 @@ static void
bi_Transform_Forward (progs_t *pr, void *_res)
{
rua_scene_resources_t *res = _res;
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
transform_t transform = rua_transform_get (res, P_ULONG (pr, 0));
R_PACKED (pr, pr_vec4_t) = Transform_Forward (transform);
}
@ -508,7 +510,7 @@ static void
bi_Transform_Right (progs_t *pr, void *_res)
{
rua_scene_resources_t *res = _res;
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
transform_t transform = rua_transform_get (res, P_ULONG (pr, 0));
R_PACKED (pr, pr_vec4_t) = Transform_Right (transform);
}
@ -516,7 +518,7 @@ static void
bi_Transform_Up (progs_t *pr, void *_res)
{
rua_scene_resources_t *res = _res;
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
transform_t transform = rua_transform_get (res, P_ULONG (pr, 0));
R_PACKED (pr, pr_vec4_t) = Transform_Up (transform);
}

View file

@ -32,6 +32,7 @@
#endif
#include "QF/scene/camera.h"
#include "QF/scene/component.h"
#include "QF/scene/scene.h"
#include "QF/scene/transform.h"
@ -40,10 +41,8 @@
void
Camera_GetViewMatrix (const camera_t *camera, mat4f_t view)
{
scene_resources_t *res = camera->scene->resources;
transform_t *transform = (transform_t *) PR_RESGET (res->transforms, camera->transform);
vec4f_t rotation = Transform_GetWorldRotation (transform);
vec4f_t position = Transform_GetWorldPosition (transform);
vec4f_t rotation = Transform_GetWorldRotation (camera->transform);
vec4f_t position = Transform_GetWorldPosition (camera->transform);
mat4fquat (view, qconjf (rotation));
// qconjf negates xyz but leaves w alone, which is what we want for
// inverting the translation (essentially, rotation+position form a

View file

@ -68,7 +68,7 @@ ECS_RegisterComponents (ecs_registry_t *registry,
}
}
VISIBLE void
VISIBLE void*
Ent_AddComponent (uint32_t ent, uint32_t comp, ecs_registry_t *registry)
{
uint32_t id = Ent_Index (ent);
@ -76,7 +76,7 @@ Ent_AddComponent (uint32_t ent, uint32_t comp, ecs_registry_t *registry)
if (pool->sparse[id] < pool->count) {
//Sys_Error ("Ent_AddComponent: component %s already on entity %x\n",
// registry->components[i].name, ent);
return;
return 0;
}
if (pool->count == pool->max_count) {
pool->max_count += COMP_GROW;
@ -88,7 +88,8 @@ Ent_AddComponent (uint32_t ent, uint32_t comp, ecs_registry_t *registry)
uint32_t ind = pool->count++;
pool->sparse[id] = ind;
pool->dense[ind] = ent;
Component_CreateElements (&registry->components[comp], pool->data, ind, 1);
return Component_CreateElements (&registry->components[comp], pool->data,
ind, 1);
}
VISIBLE void

View file

@ -41,8 +41,7 @@
#include "scn_internal.h"
static component_t ref_component = { .size = sizeof (hierref_t *) };
static component_t entity_component = { .size = sizeof (entity_t *) };
static component_t ent_component = { .size = sizeof (uint32_t) };
static component_t childCount_component = { .size = sizeof (uint32_t) };
static component_t childIndex_component = { .size = sizeof (uint32_t) };
static component_t parentIndex_component = { .size = sizeof (uint32_t) };
@ -51,10 +50,10 @@ static void
hierarchy_UpdateTransformIndices (hierarchy_t *hierarchy, uint32_t start,
int offset)
{
ecs_registry_t *reg = hierarchy->scene->reg;
for (size_t i = start; i < hierarchy->num_objects; i++) {
if (hierarchy->ref[i]) {
hierarchy->ref[i]->index += offset;
}
hierref_t *ref = Ent_GetComponent (hierarchy->ent[i], scene_href, reg);
ref->index += offset;
}
}
@ -84,10 +83,8 @@ Hierarchy_Reserve (hierarchy_t *hierarchy, uint32_t count)
new_max += 15;
new_max &= ~15;
Component_ResizeArray (&ref_component,
(void **) &hierarchy->ref, new_max);
Component_ResizeArray (&entity_component,
(void **) &hierarchy->entity, new_max);
Component_ResizeArray (&ent_component,
(void **) &hierarchy->ent, new_max);
Component_ResizeArray (&childCount_component,
(void **) &hierarchy->childCount, new_max);
Component_ResizeArray (&childIndex_component,
@ -111,10 +108,8 @@ hierarchy_open (hierarchy_t *hierarchy, uint32_t index, uint32_t count)
hierarchy->num_objects += count;
uint32_t dstIndex = index + count;
count = hierarchy->num_objects - index - count;
Component_MoveElements (&ref_component,
hierarchy->ref, dstIndex, index, count);
Component_MoveElements (&entity_component,
hierarchy->entity, dstIndex, index, count);
Component_MoveElements (&ent_component,
hierarchy->ent, dstIndex, index, count);
Component_MoveElements (&childCount_component,
hierarchy->childCount, dstIndex, index, count);
Component_MoveElements (&childIndex_component,
@ -137,10 +132,8 @@ hierarchy_close (hierarchy_t *hierarchy, uint32_t index, uint32_t count)
hierarchy->num_objects -= count;
uint32_t srcIndex = index + count;
count = hierarchy->num_objects - index;
Component_MoveElements (&ref_component,
hierarchy->ref, index, srcIndex, count);
Component_MoveElements (&entity_component,
hierarchy->entity, index, srcIndex, count);
Component_MoveElements (&ent_component,
hierarchy->ent, index, srcIndex, count);
Component_MoveElements (&childCount_component,
hierarchy->childCount, index, srcIndex, count);
Component_MoveElements (&childIndex_component,
@ -158,20 +151,20 @@ static void
hierarchy_move (hierarchy_t *dst, const hierarchy_t *src,
uint32_t dstIndex, uint32_t srcIndex, uint32_t count)
{
Component_CopyElements (&ref_component,
dst->ref, dstIndex,
src->ref, srcIndex, count);
Component_CopyElements (&entity_component,
dst->entity, dstIndex,
src->entity, srcIndex, count);
ecs_registry_t *reg = dst->scene->reg;
Component_CopyElements (&ent_component,
dst->ent, dstIndex,
src->ent, srcIndex, count);
// Actually move (as in C++ move semantics) source hierarchy object
// references so that their indices do not get updated when the objects
// are removed from the source hierarcy
memset (&src->ref[srcIndex], 0, count * sizeof(dst->ref[0]));
memset (&src->ent[srcIndex], 0, count * sizeof(dst->ent[0]));
for (uint32_t i = 0; i < count; i++) {
dst->ref[dstIndex + i]->hierarchy = dst;
dst->ref[dstIndex + i]->index = dstIndex + i;
uint32_t ent = dst->ent[dstIndex + i];
hierref_t *ref = Ent_GetComponent (ent, scene_href, reg);
ref->hierarchy = dst;
ref->index = dstIndex + i;
}
for (uint32_t i = 0; i < dst->type->num_components; i++) {
Component_CopyElements (&dst->type->components[i],
@ -184,7 +177,7 @@ static void
hierarchy_init (hierarchy_t *dst, uint32_t index,
uint32_t parentIndex, uint32_t childIndex, uint32_t count)
{
memset (&dst->ref[index], 0, count * sizeof(dst->ref[0]));
memset (&dst->ent[index], nullent, count * sizeof(uint32_t));
for (uint32_t i = 0; i < count; i++) {
dst->parentIndex[index + i] = parentIndex;
@ -207,7 +200,7 @@ hierarchy_insert (hierarchy_t *dst, const hierarchy_t *src,
// The newly added objects are always last children of the parent
// object
insertIndex = dst->childIndex[dstParent] + dst->childCount[dstParent];
// By design, all of a object's children are in one contiguous block,
// By design, all of an object's children are in one contiguous block,
// and the blocks of children for each object are ordered by their
// parents. Thus the child index of each object increases monotonically
// for each child index in the array, regardless of the level of the owning
@ -373,11 +366,7 @@ Hierarchy_Delete (hierarchy_t *hierarchy)
}
*hierarchy->prev = hierarchy->next;
scene_resources_t *res = hierarchy->scene->resources;
for (uint32_t i = 0; i < hierarchy->num_objects; i++) {
PR_RESFREE (res->transforms, hierarchy->ref[i]);
}
free (hierarchy->ref);
free (hierarchy->ent);
free (hierarchy->childCount);
free (hierarchy->childIndex);
free (hierarchy->parentIndex);
@ -386,21 +375,25 @@ Hierarchy_Delete (hierarchy_t *hierarchy)
}
free (hierarchy->components);
scene_resources_t *res = hierarchy->scene->resources;
PR_RESFREE (res->hierarchies, hierarchy);
}
hierarchy_t *
Hierarchy_Copy (scene_t *scene, const hierarchy_t *src)
{
ecs_registry_t *dstReg = scene->reg;
//ecs_registry_t *srcReg = src->scene->reg;
hierarchy_t *dst = Hierarchy_New (scene, src->type, 0);
size_t count = src->num_objects;
Hierarchy_Reserve (dst, count);
for (size_t i = 0; i < count; i++) {
dst->ref[i] = __transform_alloc (scene);
dst->ref[i]->hierarchy = dst;
dst->ref[i]->index = i;
dst->ent[i] = ECS_NewEntity (dstReg);
hierref_t *ref = Ent_AddComponent (dst->ent[i], scene_href, dstReg);
ref->hierarchy = dst;
ref->index = i;
}
Component_CopyElements (&childCount_component,

View file

@ -36,16 +36,63 @@
#endif
#include "QF/mathlib.h"
#include "QF/progs.h" // for PR_RESMAP
#include "QF/sys.h"
#include "QF/model.h"
#include "QF/scene/component.h"
#include "QF/scene/entity.h"
#include "QF/scene/scene.h"
#include "QF/scene/transform.h"
#include "scn_internal.h"
static void
create_active (void *_active)
{
byte *active = _active;
*active = 1;
}
static void
create_old_origin (void *_old_origin)
{
vec4f_t *old_origin = _old_origin;
*old_origin = (vec4f_t) {0, 0, 0, 1};
}
static const component_t scene_components[] = {
[scene_href] = {
.size = sizeof (hierref_t),
.create = 0,//create_href,
.name = "href",
},
[scene_animation] = {
.size = sizeof (animation_t),
.create = 0,//create_animation,
.name = "animation",
},
[scene_visibility] = {
.size = sizeof (visibility_t),
.create = 0,//create_visibility,
.name = "visibility",
},
[scene_renderer] = {
.size = sizeof (renderer_t),
.create = 0,//create_renderer,
.name = "renderer",
},
[scene_active] = {
.size = sizeof (byte),
.create = create_active,
.name = "active",
},
[scene_old_origin] = {
.size = sizeof (vec4f_t),
.create = create_old_origin,
.name = "old_origin",
},
};
static byte empty_visdata[] = { 0x01 };
static mleaf_t empty_leafs[] = {
@ -104,11 +151,12 @@ static model_t empty_world = {
scene_t *
Scene_NewScene (void)
{
scene_t *scene;
scene_resources_t *res;
scene_t *scene = calloc (1, sizeof (scene_t));
scene = calloc (1, sizeof (scene_t));
res = calloc (1, sizeof (scene_resources_t));
scene->reg = ECS_NewRegistry ();
ECS_RegisterComponents (scene->reg, scene_components, scene_num_components);
scene_resources_t *res = calloc (1, sizeof (scene_resources_t));
*(scene_resources_t **)&scene->resources = res;
scene->worldmodel = &empty_world;
@ -119,90 +167,38 @@ Scene_NewScene (void)
void
Scene_DeleteScene (scene_t *scene)
{
Scene_FreeAllEntities (scene);
scene_resources_t *res = scene->resources;
for (unsigned i = 0; i < res->entities._size; i++) {
free (res->entities._map[i]);
}
free (res->entities._map);
ECS_DelRegistry (scene->reg);
free (scene->resources);
free (scene);
}
entity_t *
entity_t
Scene_CreateEntity (scene_t *scene)
{
scene_resources_t *res = scene->resources;
transform_t trans = Transform_New (scene, nulltransform);
uint32_t id = trans.id;
entity_t *ent = PR_RESNEW (res->entities);
ent->transform = Transform_New (scene, 0);
ent->id = PR_RESINDEX (res->entities, ent);
Ent_AddComponent (id, scene_href, scene->reg);
Ent_AddComponent (id, scene_animation, scene->reg);
Ent_AddComponent (id, scene_visibility, scene->reg);
Ent_AddComponent (id, scene_renderer, scene->reg);
Ent_AddComponent (id, scene_active, scene->reg);
Ent_AddComponent (id, scene_old_origin, scene->reg);
hierarchy_t *h = ent->transform->ref.hierarchy;
h->entity[ent->transform->ref.index] = ent;
renderer_t *renderer = Ent_GetComponent (id, scene_renderer, scene->reg);
QuatSet (1, 1, 1, 1, renderer->colormod);
QuatSet (1, 1, 1, 1, ent->renderer.colormod);
return ent;
}
entity_t *
Scene_GetEntity (scene_t *scene, int id)
{
scene_resources_t *res = scene->resources;
return PR_RESGET (res->entities, id);
}
static void
destroy_entity (scene_t *scene, entity_t *ent)
{
scene_resources_t *res = scene->resources;
// ent->transform will be trampled by the loop below
transform_t *transform = ent->transform;
// Transform_Delete takes care of all hierarchy stuff (transforms
// themselves, name strings, hierarchy table)
hierarchy_t *h = transform->ref.hierarchy;
for (size_t i = 0; i < h->num_objects; i++) {
entity_t *e = h->entity[0];
e->transform = 0;
PR_RESFREE (res->entities, ent);
}
Transform_Delete (scene, transform);
return (entity_t) { .reg = scene->reg, .id = id };
}
void
Scene_DestroyEntity (scene_t *scene, entity_t *ent)
Scene_DestroyEntity (scene_t *scene, entity_t ent)
{
scene_resources_t *res = scene->resources;
if (PR_RESGET (res->entities, ent->id) != ent) {
Sys_Error ("Scene_DestroyEntity: entity not owned by scene");
}
// pull the transform out of the hierarchy to make it easier to destory
// all the child entities
Transform_SetParent (scene, ent->transform, 0);
destroy_entity (scene, ent);
ECS_DelEntity (scene->reg, ent.id);
}
void
Scene_FreeAllEntities (scene_t *scene)
{
while (scene->hierarchies) {
hierarchy_t *h = scene->hierarchies;
// deleting the root entity deletes all child entities
entity_t *ent = h->entity[0];
destroy_entity (scene, ent);
}
scene_resources_t *res = scene->resources;
PR_RESRESET (res->entities);
}
transform_t *
Scene_GetTransform (scene_t *scene, int id)
{
scene_resources_t *res = scene->resources;
return (transform_t *) PR_RESGET (res->transforms, id);
}

View file

@ -42,15 +42,18 @@ mat4_equal (const mat4f_t a, const mat4f_t b)
}
static int
check_hierarchy_size (hierarchy_t *h, uint32_t size)
check_hierarchy_size (transform_t t, uint32_t size)
{
hierarchy_t *h = Transform_GetRef (t)->hierarchy;
if (h->num_objects != size) {
printf ("hierarchy does not have exactly %u transform\n", size);
return 0;
}
char **name = h->components[transform_type_name];
ecs_registry_t *reg = h->scene->reg;
for (uint32_t i = 0; i < h->num_objects; i++) {
if (h->ref[i]->hierarchy != h) {
hierref_t *ref = Ent_GetComponent (h->ent[i], scene_href, reg);
if (ref->hierarchy != h) {
printf ("transform %d (%s) does not point to hierarchy\n",
i, name[i]);
}
@ -59,22 +62,25 @@ check_hierarchy_size (hierarchy_t *h, uint32_t size)
}
static void
dump_hierarchy (hierarchy_t *h)
dump_hierarchy (transform_t t)
{
hierarchy_t *h = Transform_GetRef (t)->hierarchy;
char **name = h->components[transform_type_name];
ecs_registry_t *reg = h->scene->reg;
for (uint32_t i = 0; i < h->num_objects; i++) {
printf ("%2d: %5s %2u %2u %2u %2u\n", i, name[i],
h->ref[i]->index, h->parentIndex[i],
hierref_t *ref = Ent_GetComponent (h->ent[i], scene_href, reg);
printf ("%2d: %5s %2u %2u %2u %2u %2u\n", i, name[i], h->ent[i],
ref->index, h->parentIndex[i],
h->childIndex[i], h->childCount[i]);
}
puts ("");
}
static int
check_indices (transform_t *transform, uint32_t index, uint32_t parentIndex,
check_indices (transform_t transform, uint32_t index, uint32_t parentIndex,
uint32_t childIndex, uint32_t childCount)
{
__auto_type ref = &transform->ref;
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
char **name = h->components[transform_type_name];
if (ref->index != index) {
@ -104,14 +110,18 @@ check_indices (transform_t *transform, uint32_t index, uint32_t parentIndex,
static int
test_single_transform (void)
{
transform_t *transform = Transform_New (scene, 0);
transform_t transform = Transform_New (scene, (transform_t) {});
hierarchy_t *h;
if (!transform) {
if (!transform.reg || transform.id == nullent) {
printf ("Transform_New returned null\n");
return 1;
}
if (!(h = transform->ref.hierarchy)) {
if (!Transform_GetRef (transform)) {
printf ("Transform_GetRef returned null\n");
return 1;
}
if (!(h = Transform_GetRef (transform)->hierarchy)) {
printf ("New transform has no hierarchy\n");
return 1;
}
@ -121,7 +131,7 @@ test_single_transform (void)
mat4f_t *worldInverse = h->components[transform_type_worldInverse];
vec4f_t *localRotation = h->components[transform_type_localRotation];
vec4f_t *localScale = h->components[transform_type_localScale];
if (!check_hierarchy_size (h, 1)) { return 1; }
if (!check_hierarchy_size (transform, 1)) { return 1; }
if (!check_indices (transform, 0, nullent, 1, 0)) { return 1; }
if (!mat4_equal (localMatrix[0], identity)
@ -139,7 +149,7 @@ test_single_transform (void)
}
// Delete the hierarchy directly as setparent isn't fully tested
Hierarchy_Delete (transform->ref.hierarchy);
Hierarchy_Delete (h);
return 0;
}
@ -147,20 +157,21 @@ test_single_transform (void)
static int
test_parent_child_init (void)
{
transform_t *parent = Transform_New (scene, 0);
transform_t *child = Transform_New (scene, parent);
transform_t parent = Transform_New (scene, (transform_t) {});
transform_t child = Transform_New (scene, parent);
if (parent->ref.hierarchy != child->ref.hierarchy) {
if (Transform_GetRef (parent)->hierarchy
!= Transform_GetRef (child)->hierarchy) {
printf ("parent and child transforms have separate hierarchies\n");
return 1;
}
if (!check_hierarchy_size (parent->ref.hierarchy, 2)) { return 1; }
if (!check_hierarchy_size (parent, 2)) { return 1; }
if (!check_indices (parent, 0, nullent, 1, 1)) { return 1; }
if (!check_indices (child, 1, 0, 2, 0)) { return 1; }
hierarchy_t *h = parent->ref.hierarchy;
hierarchy_t *h = Transform_GetRef (parent)->hierarchy;
mat4f_t *localMatrix = h->components[transform_type_localMatrix];
mat4f_t *localInverse = h->components[transform_type_localInverse];
mat4f_t *worldMatrix = h->components[transform_type_worldMatrix];
@ -196,7 +207,7 @@ test_parent_child_init (void)
}
// Delete the hierarchy directly as setparent isn't fully tested
Hierarchy_Delete (parent->ref.hierarchy);
Hierarchy_Delete (Transform_GetRef (parent)->hierarchy);
return 0;
}
@ -204,8 +215,8 @@ test_parent_child_init (void)
static int
test_parent_child_setparent (void)
{
transform_t *parent = Transform_New (scene, 0);
transform_t *child = Transform_New (scene, 0);
transform_t parent = Transform_New (scene, (transform_t) {});
transform_t child = Transform_New (scene, (transform_t) {});
Transform_SetName (parent, "parent");
Transform_SetName (child, "child");
@ -213,25 +224,27 @@ test_parent_child_setparent (void)
if (!check_indices (parent, 0, nullent, 1, 0)) { return 1; }
if (!check_indices (child, 0, nullent, 1, 0)) { return 1; }
if (parent->ref.hierarchy == child->ref.hierarchy) {
if (Transform_GetRef (parent)->hierarchy
== Transform_GetRef (child)->hierarchy) {
printf ("parent and child transforms have same hierarchy before"
" set paret\n");
return 1;
}
Transform_SetParent (scene,child, parent);
Transform_SetParent (scene, child, parent);
if (parent->ref.hierarchy != child->ref.hierarchy) {
if (Transform_GetRef (parent)->hierarchy
!= Transform_GetRef (child)->hierarchy) {
printf ("parent and child transforms have separate hierarchies\n");
return 1;
}
if (!check_hierarchy_size (parent->ref.hierarchy, 2)) { return 1; }
if (!check_hierarchy_size (parent, 2)) { return 1; }
if (!check_indices (parent, 0, nullent, 1, 1)) { return 1; }
if (!check_indices (child, 1, 0, 2, 0)) { return 1; }
hierarchy_t *h = parent->ref.hierarchy;
hierarchy_t *h = Transform_GetRef (parent)->hierarchy;
mat4f_t *localMatrix = h->components[transform_type_localMatrix];
mat4f_t *localInverse = h->components[transform_type_localInverse];
mat4f_t *worldMatrix = h->components[transform_type_worldMatrix];
@ -267,7 +280,7 @@ test_parent_child_setparent (void)
}
// Delete the hierarchy directly as setparent isn't fully tested
Hierarchy_Delete (parent->ref.hierarchy);
Hierarchy_Delete (Transform_GetRef (parent)->hierarchy);
return 0;
}
@ -277,17 +290,17 @@ test_build_hierarchy (void)
{
printf ("test_build_hierarchy\n");
transform_t *root = Transform_NewNamed (scene, 0, "root");
transform_t *A = Transform_NewNamed (scene, root, "A");
transform_t *B = Transform_NewNamed (scene, root, "B");
transform_t *C = Transform_NewNamed (scene, root, "C");
transform_t root = Transform_NewNamed (scene, (transform_t) {}, "root");
transform_t A = Transform_NewNamed (scene, root, "A");
transform_t B = Transform_NewNamed (scene, root, "B");
transform_t C = Transform_NewNamed (scene, root, "C");
if (!check_indices (root, 0, nullent, 1, 3)) { return 1; }
if (!check_indices (A, 1, 0, 4, 0)) { return 1; }
if (!check_indices (B, 2, 0, 4, 0)) { return 1; }
if (!check_indices (C, 3, 0, 4, 0)) { return 1; }
transform_t *B1 = Transform_NewNamed (scene, B, "B1");
transform_t B1 = Transform_NewNamed (scene, B, "B1");
if (!check_indices (root, 0, nullent, 1, 3)) { return 1; }
if (!check_indices ( A, 1, 0, 4, 0)) { return 1; }
@ -295,7 +308,7 @@ test_build_hierarchy (void)
if (!check_indices ( C, 3, 0, 5, 0)) { return 1; }
if (!check_indices (B1, 4, 2, 5, 0)) { return 1; }
transform_t *A1 = Transform_NewNamed (scene, A, "A1");
transform_t A1 = Transform_NewNamed (scene, A, "A1");
if (!check_indices (root, 0, nullent, 1, 3)) { return 1; }
if (!check_indices ( A, 1, 0, 4, 1)) { return 1; }
@ -303,13 +316,13 @@ test_build_hierarchy (void)
if (!check_indices ( C, 3, 0, 6, 0)) { return 1; }
if (!check_indices (A1, 4, 1, 6, 0)) { return 1; }
if (!check_indices (B1, 5, 2, 6, 0)) { return 1; }
transform_t *A1a = Transform_NewNamed (scene, A1, "A1a");
transform_t *B2 = Transform_NewNamed (scene, B, "B2");
transform_t *A2 = Transform_NewNamed (scene, A, "A2");
transform_t *B3 = Transform_NewNamed (scene, B, "B3");
transform_t *B2a = Transform_NewNamed (scene, B2, "B2a");
transform_t A1a = Transform_NewNamed (scene, A1, "A1a");
transform_t B2 = Transform_NewNamed (scene, B, "B2");
transform_t A2 = Transform_NewNamed (scene, A, "A2");
transform_t B3 = Transform_NewNamed (scene, B, "B3");
transform_t B2a = Transform_NewNamed (scene, B2, "B2a");
if (!check_hierarchy_size (root->ref.hierarchy, 11)) { return 1; }
if (!check_hierarchy_size (root, 11)) { return 1; }
if (!check_indices (root, 0, nullent, 1, 3)) { return 1; }
if (!check_indices ( A, 1, 0, 4, 2)) { return 1; }
@ -323,9 +336,9 @@ test_build_hierarchy (void)
if (!check_indices (A1a, 9, 4, 11, 0)) { return 1; }
if (!check_indices (B2a, 10, 7, 11, 0)) { return 1; }
transform_t *D = Transform_NewNamed (scene, root, "D");
transform_t D = Transform_NewNamed (scene, root, "D");
if (!check_hierarchy_size (root->ref.hierarchy, 12)) { return 1; }
if (!check_hierarchy_size (root, 12)) { return 1; }
if (!check_indices (root, 0, nullent, 1, 4)) { return 1; }
if (!check_indices ( A, 1, 0, 5, 2)) { return 1; }
@ -340,10 +353,10 @@ test_build_hierarchy (void)
if (!check_indices (A1a, 10, 5, 12, 0)) { return 1; }
if (!check_indices (B2a, 11, 8, 12, 0)) { return 1; }
dump_hierarchy (root->ref.hierarchy);
transform_t *C1 = Transform_NewNamed (scene, C, "C1");
dump_hierarchy (root->ref.hierarchy);
if (!check_hierarchy_size (root->ref.hierarchy, 13)) { return 1; }
dump_hierarchy (root);
transform_t C1 = Transform_NewNamed (scene, C, "C1");
dump_hierarchy (root);
if (!check_hierarchy_size (root, 13)) { return 1; }
if (!check_indices (root, 0, nullent, 1, 4)) { return 1; }
if (!check_indices ( A, 1, 0, 5, 2)) { return 1; }
@ -360,7 +373,7 @@ test_build_hierarchy (void)
if (!check_indices (B2a, 12, 8, 13, 0)) { return 1; }
// Delete the hierarchy directly as setparent isn't fully tested
Hierarchy_Delete (root->ref.hierarchy);
Hierarchy_Delete (Transform_GetRef (root)->hierarchy);
return 0;
}
@ -370,21 +383,21 @@ test_build_hierarchy2 (void)
{
printf ("test_build_hierarchy2\n");
transform_t *root = Transform_NewNamed (scene, 0, "root");
transform_t *A = Transform_NewNamed (scene, root, "A");
transform_t *B = Transform_NewNamed (scene, root, "B");
transform_t *C = Transform_NewNamed (scene, root, "C");
transform_t *B1 = Transform_NewNamed (scene, B, "B1");
transform_t *A1 = Transform_NewNamed (scene, A, "A1");
transform_t *A1a = Transform_NewNamed (scene, A1, "A1a");
transform_t *B2 = Transform_NewNamed (scene, B, "B2");
transform_t *A2 = Transform_NewNamed (scene, A, "A2");
transform_t *B3 = Transform_NewNamed (scene, B, "B3");
transform_t *B2a = Transform_NewNamed (scene, B2, "B2a");
transform_t *D = Transform_NewNamed (scene, root, "D");
transform_t *C1 = Transform_NewNamed (scene, C, "C1");
transform_t root = Transform_NewNamed (scene, (transform_t) {}, "root");
transform_t A = Transform_NewNamed (scene, root, "A");
transform_t B = Transform_NewNamed (scene, root, "B");
transform_t C = Transform_NewNamed (scene, root, "C");
transform_t B1 = Transform_NewNamed (scene, B, "B1");
transform_t A1 = Transform_NewNamed (scene, A, "A1");
transform_t A1a = Transform_NewNamed (scene, A1, "A1a");
transform_t B2 = Transform_NewNamed (scene, B, "B2");
transform_t A2 = Transform_NewNamed (scene, A, "A2");
transform_t B3 = Transform_NewNamed (scene, B, "B3");
transform_t B2a = Transform_NewNamed (scene, B2, "B2a");
transform_t D = Transform_NewNamed (scene, root, "D");
transform_t C1 = Transform_NewNamed (scene, C, "C1");
if (!check_hierarchy_size (root->ref.hierarchy, 13)) { return 1; }
if (!check_hierarchy_size (root, 13)) { return 1; }
if (!check_indices (root, 0, nullent, 1, 4)) { return 1; }
if (!check_indices ( A, 1, 0, 5, 2)) { return 1; }
@ -400,21 +413,21 @@ test_build_hierarchy2 (void)
if (!check_indices (A1a, 11, 5, 13, 0)) { return 1; }
if (!check_indices (B2a, 12, 8, 13, 0)) { return 1; }
transform_t *T = Transform_NewNamed (scene, 0, "T");
transform_t *X = Transform_NewNamed (scene, T, "X");
transform_t *Y = Transform_NewNamed (scene, T, "Y");
transform_t *Z = Transform_NewNamed (scene, T, "Z");
transform_t *Y1 = Transform_NewNamed (scene, Y, "Y1");
transform_t *X1 = Transform_NewNamed (scene, X, "X1");
transform_t *X1a = Transform_NewNamed (scene, X1, "X1a");
transform_t *Y2 = Transform_NewNamed (scene, Y, "Y2");
transform_t *X2 = Transform_NewNamed (scene, X, "X2");
transform_t *Y3 = Transform_NewNamed (scene, Y, "Y3");
transform_t *Y2a = Transform_NewNamed (scene, Y2, "Y2a");
transform_t *Z1 = Transform_NewNamed (scene, Z, "Z1");
transform_t T = Transform_NewNamed (scene, (transform_t) {}, "T");
transform_t X = Transform_NewNamed (scene, T, "X");
transform_t Y = Transform_NewNamed (scene, T, "Y");
transform_t Z = Transform_NewNamed (scene, T, "Z");
transform_t Y1 = Transform_NewNamed (scene, Y, "Y1");
transform_t X1 = Transform_NewNamed (scene, X, "X1");
transform_t X1a = Transform_NewNamed (scene, X1, "X1a");
transform_t Y2 = Transform_NewNamed (scene, Y, "Y2");
transform_t X2 = Transform_NewNamed (scene, X, "X2");
transform_t Y3 = Transform_NewNamed (scene, Y, "Y3");
transform_t Y2a = Transform_NewNamed (scene, Y2, "Y2a");
transform_t Z1 = Transform_NewNamed (scene, Z, "Z1");
dump_hierarchy (T->ref.hierarchy);
if (!check_hierarchy_size (T->ref.hierarchy, 12)) { return 1; }
dump_hierarchy (T);
if (!check_hierarchy_size (T, 12)) { return 1; }
if (!check_indices ( T, 0, nullent, 1, 3)) { return 1; }
if (!check_indices ( X, 1, 0, 4, 2)) { return 1; }
@ -429,11 +442,11 @@ test_build_hierarchy2 (void)
if (!check_indices (X1a, 10, 4, 12, 0)) { return 1; }
if (!check_indices (Y2a, 11, 7, 12, 0)) { return 1; }
Transform_SetParent (scene,T, B);
Transform_SetParent (scene, T, B);
dump_hierarchy (root->ref.hierarchy);
dump_hierarchy (root);
if (!check_hierarchy_size (root->ref.hierarchy, 25)) { return 1; }
if (!check_hierarchy_size (root, 25)) { return 1; }
if (!check_indices (root, 0, nullent, 1, 4)) { return 1; }
if (!check_indices ( A, 1, 0, 5, 2)) { return 1; }
@ -461,12 +474,12 @@ test_build_hierarchy2 (void)
if (!check_indices (X1a, 23, 17, 25, 0)) { return 1; }
if (!check_indices (Y2a, 24, 20, 25, 0)) { return 1; }
Transform_SetParent (scene,Y, 0);
Transform_SetParent (scene, Y, (transform_t) {});
dump_hierarchy (root->ref.hierarchy);
dump_hierarchy (Y->ref.hierarchy);
if (!check_hierarchy_size (root->ref.hierarchy, 20)) { return 1; }
if (!check_hierarchy_size (Y->ref.hierarchy, 5)) { return 1; }
dump_hierarchy (root);
dump_hierarchy (Y);
if (!check_hierarchy_size (root, 20)) { return 1; }
if (!check_hierarchy_size (Y, 5)) { return 1; }
if (!check_indices (root, 0, nullent, 1, 4)) { return 1; }
if (!check_indices ( A, 1, 0, 5, 2)) { return 1; }
@ -496,15 +509,15 @@ test_build_hierarchy2 (void)
if (!check_indices (Y2a, 4, 2, 5, 0)) { return 1; }
// Delete the hierarchy directly as setparent isn't fully tested
Hierarchy_Delete (root->ref.hierarchy);
Hierarchy_Delete (Y->ref.hierarchy);
Hierarchy_Delete (Transform_GetRef (root)->hierarchy);
Hierarchy_Delete (Transform_GetRef (Y)->hierarchy);
return 0;
}
static int
check_vector (const transform_t *transform,
vec4f_t (*func) (const transform_t *t),
check_vector (transform_t transform,
vec4f_t (*func) (transform_t t),
vec4f_t expect, const char *msg)
{
vec4f_t res = func(transform);
@ -520,11 +533,11 @@ check_vector (const transform_t *transform,
static int
test_frames (void)
{
transform_t *root = Transform_NewNamed (scene, 0, "root");
transform_t *A = Transform_NewNamed (scene, root, "A");
transform_t *B = Transform_NewNamed (scene, root, "B");
transform_t *A1 = Transform_NewNamed (scene, A, "A1");
transform_t *B1 = Transform_NewNamed (scene, B, "B1");
transform_t root = Transform_NewNamed (scene, (transform_t) {}, "root");
transform_t A = Transform_NewNamed (scene, root, "A");
transform_t B = Transform_NewNamed (scene, root, "B");
transform_t A1 = Transform_NewNamed (scene, A, "A1");
transform_t B1 = Transform_NewNamed (scene, B, "B1");
Transform_SetLocalPosition (root, (vec4f_t) { 0, 0, 1, 1 });
Transform_SetLocalPosition (A, (vec4f_t) { 1, 0, 0, 1 });
@ -536,7 +549,7 @@ test_frames (void)
Transform_SetLocalPosition (B1, (vec4f_t) { 0, 1, 0, 1 });
Transform_SetLocalRotation (B1, (vec4f_t) { -0.5, 0.5, -0.5, 0.5 });
hierarchy_t *h = root->ref.hierarchy;
hierarchy_t *h = Transform_GetRef (root)->hierarchy;
mat4f_t *localMatrix = h->components[transform_type_localMatrix];
mat4f_t *localInverse = h->components[transform_type_localInverse];
mat4f_t *worldMatrix = h->components[transform_type_worldMatrix];

View file

@ -133,17 +133,6 @@ static const hierarchy_type_t transform_type = {
.components = transform_components,
};
hierref_t *
__transform_alloc (scene_t *scene)
{
scene_resources_t *res = scene->resources;
hierref_t *ref = PR_RESNEW_NC (res->transforms);
ref->id = PR_RESINDEX (res->transforms, ref);
ref->hierarchy = 0;
ref->index = 0;
return ref;
}
static void
transform_calcLocalInverse (hierarchy_t *h, uint32_t index)
{
@ -231,73 +220,81 @@ Transform_UpdateMatrices (hierarchy_t *h)
memset (modified, 0, h->num_objects);
}
transform_t *
Transform_New (scene_t *scene, transform_t *parent)
transform_t
Transform_New (scene_t *scene, transform_t parent)
{
hierref_t *transform = __transform_alloc (scene);
__auto_type ref = (hierref_t *) transform;
ecs_registry_t *reg = scene->reg;
uint32_t transform = ECS_NewEntity (reg);
hierref_t *ref = Ent_AddComponent (transform, scene_href, reg);
if (parent) {
ref->hierarchy = parent->ref.hierarchy;
ref->index = Hierarchy_InsertHierarchy (parent->ref.hierarchy, 0,
parent->ref.index, 0);
if (parent.reg && parent.id != nullent) {
hierref_t *pref = Transform_GetRef (parent);
ref->hierarchy = pref->hierarchy;
ref->index = Hierarchy_InsertHierarchy (pref->hierarchy, 0,
pref->index, 0);
} else {
ref->hierarchy = Hierarchy_New (scene, &transform_type, 1);
ref->index = 0;
}
ref->hierarchy->ref[ref->index] = transform;
ref->hierarchy->ent[ref->index] = transform;
Transform_UpdateMatrices (ref->hierarchy);
return (transform_t *) transform;
return (transform_t) { .reg = reg, .id = transform, .comp = scene_href };
}
void
Transform_Delete (scene_t *scene, transform_t *transform)
Transform_Delete (scene_t *scene, transform_t transform)
{
if (transform->ref.index != 0) {
hierref_t *ref = Transform_GetRef (transform);
if (ref->index != 0) {
// The transform is not the root, so pull it out of its current
// hierarchy so deleting it is easier
Transform_SetParent (scene, transform, 0);
Transform_SetParent (scene, transform, (transform_t) {});
}
// Takes care of freeing the transforms
Hierarchy_Delete (transform->ref.hierarchy);
Hierarchy_Delete (ref->hierarchy);
}
transform_t *
Transform_NewNamed (scene_t *scene, transform_t *parent, const char *name)
transform_t
Transform_NewNamed (scene_t *scene, transform_t parent, const char *name)
{
transform_t *transform = Transform_New (scene, parent);
transform_t transform = Transform_New (scene, parent);
Transform_SetName (transform, name);
return transform;
}
void
Transform_SetParent (scene_t *scene, transform_t *transform,
transform_t *parent)
Transform_SetParent (scene_t *scene, transform_t transform,
transform_t parent)
{
if (parent) {
hierarchy_t *hierarchy = transform->ref.hierarchy;
uint32_t index = transform->ref.index;
Hierarchy_InsertHierarchy (parent->ref.hierarchy, hierarchy,
parent->ref.index, index);
Hierarchy_RemoveHierarchy (hierarchy, index);
if (!hierarchy->num_objects) {
Hierarchy_Delete (hierarchy);
if (parent.reg && parent.id != nullent) {
__auto_type ref = Transform_GetRef (transform);
__auto_type tref = *ref;
__auto_type pref = Transform_GetRef (parent);
ref->index = Hierarchy_InsertHierarchy (pref->hierarchy,
tref.hierarchy,
pref->index, tref.index);
ref->hierarchy = pref->hierarchy;
Hierarchy_RemoveHierarchy (tref.hierarchy, tref.index);
if (!tref.hierarchy->num_objects) {
Hierarchy_Delete (tref.hierarchy);
}
} else {
__auto_type ref = Transform_GetRef (transform);
__auto_type tref = *ref;
// null parent -> make transform root
if (!transform->ref.index) {
if (!tref.index) {
// already root
return;
}
hierarchy_t *hierarchy = transform->ref.hierarchy;
uint32_t index = transform->ref.index;
hierarchy_t *new_hierarchy = Hierarchy_New (scene, &transform_type, 0);
Hierarchy_InsertHierarchy (new_hierarchy, hierarchy, nullent,
index);
Hierarchy_RemoveHierarchy (hierarchy, index);
ref->hierarchy = Hierarchy_New (scene, &transform_type, 0);
Hierarchy_InsertHierarchy (ref->hierarchy, tref.hierarchy, nullent,
tref.index);
Hierarchy_RemoveHierarchy (tref.hierarchy, tref.index);
if (!tref.hierarchy->num_objects) {
Hierarchy_Delete (tref.hierarchy);
}
}
__auto_type ref = (const hierref_t *) transform;
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
byte *modified = h->components[transform_type_modified];
modified[ref->index] = 1;
@ -305,9 +302,9 @@ Transform_SetParent (scene_t *scene, transform_t *transform,
}
void
Transform_SetName (transform_t *transform, const char *_name)
Transform_SetName (transform_t transform, const char *_name)
{
__auto_type ref = (const hierref_t *) transform;
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
char **name = h->components[transform_type_name];
//FIXME create a string pool (similar to qfcc's, or even move that to util)
@ -318,18 +315,18 @@ Transform_SetName (transform_t *transform, const char *_name)
}
void
Transform_SetTag (transform_t *transform, uint32_t _tag)
Transform_SetTag (transform_t transform, uint32_t _tag)
{
__auto_type ref = (const hierref_t *) transform;
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
uint32_t *tag = h->components[transform_type_tag];
tag[ref->index] = _tag;
}
void
Transform_SetLocalPosition (transform_t *transform, vec4f_t position)
Transform_SetLocalPosition (transform_t transform, vec4f_t position)
{
__auto_type ref = (const hierref_t *) transform;
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
mat4f_t *localMatrix = h->components[transform_type_localMatrix];
byte *modified = h->components[transform_type_modified];
@ -339,9 +336,9 @@ Transform_SetLocalPosition (transform_t *transform, vec4f_t position)
}
void
Transform_SetLocalRotation (transform_t *transform, vec4f_t rotation)
Transform_SetLocalRotation (transform_t transform, vec4f_t rotation)
{
__auto_type ref = (const hierref_t *) transform;
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
mat4f_t *localMatrix = h->components[transform_type_localMatrix];
vec4f_t *localRotation = h->components[transform_type_localRotation];
@ -361,9 +358,9 @@ Transform_SetLocalRotation (transform_t *transform, vec4f_t rotation)
}
void
Transform_SetLocalScale (transform_t *transform, vec4f_t scale)
Transform_SetLocalScale (transform_t transform, vec4f_t scale)
{
__auto_type ref = (const hierref_t *) transform;
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
mat4f_t *localMatrix = h->components[transform_type_localMatrix];
vec4f_t *localRotation = h->components[transform_type_localRotation];
@ -383,9 +380,9 @@ Transform_SetLocalScale (transform_t *transform, vec4f_t scale)
}
void
Transform_SetWorldPosition (transform_t *transform, vec4f_t position)
Transform_SetWorldPosition (transform_t transform, vec4f_t position)
{
__auto_type ref = (const hierref_t *) transform;
__auto_type ref = Transform_GetRef (transform);
if (ref->index) {
hierarchy_t *h = ref->hierarchy;
mat4f_t *worldInverse = h->components[transform_type_worldInverse];
@ -396,9 +393,9 @@ Transform_SetWorldPosition (transform_t *transform, vec4f_t position)
}
void
Transform_SetWorldRotation (transform_t *transform, vec4f_t rotation)
Transform_SetWorldRotation (transform_t transform, vec4f_t rotation)
{
__auto_type ref = (const hierref_t *) transform;
__auto_type ref = Transform_GetRef (transform);
if (ref->index) {
hierarchy_t *h = ref->hierarchy;
vec4f_t *worldRotation = h->components[transform_type_worldRotation];
@ -409,10 +406,10 @@ Transform_SetWorldRotation (transform_t *transform, vec4f_t rotation)
}
void
Transform_SetLocalTransform (transform_t *transform, vec4f_t scale,
Transform_SetLocalTransform (transform_t transform, vec4f_t scale,
vec4f_t rotation, vec4f_t position)
{
__auto_type ref = (const hierref_t *) transform;
__auto_type ref = Transform_GetRef (transform);
hierarchy_t *h = ref->hierarchy;
mat4f_t *localMatrix = h->components[transform_type_localMatrix];
vec4f_t *localRotation = h->components[transform_type_localRotation];

View file

@ -77,7 +77,7 @@ glRect_t gl_lightmap_rectchange[MAX_LIGHTMAPS];
static int lmshift = 7;
void (*gl_R_BuildLightMap) (const transform_t *transform, mod_brush_t *brush,
void (*gl_R_BuildLightMap) (const vec4f_t *transform, mod_brush_t *brush,
msurface_t *surf);
void
@ -92,7 +92,7 @@ gl_lightmap_init (void)
}
static inline void
R_AddDynamicLights_1 (const transform_t *transform, msurface_t *surf)
R_AddDynamicLights_1 (const vec4f_t *transform, msurface_t *surf)
{
float dist;
unsigned int maxdist, maxdist2, maxdist3;
@ -110,7 +110,7 @@ R_AddDynamicLights_1 (const transform_t *transform, msurface_t *surf)
if (transform) {
//FIXME give world entity a transform
entorigin = Transform_GetWorldPosition (transform);
entorigin = transform[3];
}
for (lnum = 0; lnum < r_maxdlights; lnum++) {
@ -163,7 +163,7 @@ R_AddDynamicLights_1 (const transform_t *transform, msurface_t *surf)
}
static inline void
R_AddDynamicLights_3 (const transform_t *transform, msurface_t *surf)
R_AddDynamicLights_3 (const vec4f_t *transform, msurface_t *surf)
{
float dist;
unsigned int maxdist, maxdist2, maxdist3;
@ -180,7 +180,7 @@ R_AddDynamicLights_3 (const transform_t *transform, msurface_t *surf)
tmax = (surf->extents[1] >> 4) + 1;
if (transform) {
entorigin = Transform_GetWorldPosition (transform);
entorigin = transform[3];
}
for (lnum = 0; lnum < r_maxdlights; lnum++) {
@ -236,7 +236,7 @@ R_AddDynamicLights_3 (const transform_t *transform, msurface_t *surf)
}
static void
R_BuildLightMap_1 (const transform_t *transform, mod_brush_t *brush,
R_BuildLightMap_1 (const vec4f_t *transform, mod_brush_t *brush,
msurface_t *surf)
{
byte *dest;
@ -292,7 +292,7 @@ R_BuildLightMap_1 (const transform_t *transform, mod_brush_t *brush,
}
static void
R_BuildLightMap_3 (const transform_t *transform, mod_brush_t *brush,
R_BuildLightMap_3 (const vec4f_t *transform, mod_brush_t *brush,
msurface_t *surf)
{
byte *dest;
@ -354,7 +354,7 @@ R_BuildLightMap_3 (const transform_t *transform, mod_brush_t *brush,
}
static void
R_BuildLightMap_4 (const transform_t *transform, mod_brush_t *brush,
R_BuildLightMap_4 (const vec4f_t *transform, mod_brush_t *brush,
msurface_t *surf)
{
byte *dest;
@ -432,7 +432,7 @@ gl_R_BlendLightmaps (void)
for (sc = gl_lightmap_polys; sc; sc = sc->lm_chain) {
if (sc->transform) {
qfglPushMatrix ();
qfglLoadMatrixf (sc->transform);
qfglLoadMatrixf ((vec_t*)&sc->transform[0]);//FIXME
}
for (p = sc->surface->polys; p; p = p->next) {
qfglBegin (GL_POLYGON);

View file

@ -41,7 +41,9 @@
#include "QF/skin.h"
#include "QF/scene/component.h"
#include "QF/scene/entity.h"
#include "QF/scene/scene.h"
#include "QF/GL/defines.h"
#include "QF/GL/funcs.h"
@ -182,8 +184,8 @@ GL_DrawAliasFrameMulti (vert_order_t *vo)
Standard shadow drawing (triangles version)
*/
static void
GL_DrawAliasShadowTri (const transform_t *transform,
const aliashdr_t *paliashdr, const vert_order_t *vo)
GL_DrawAliasShadowTri (transform_t transform, const aliashdr_t *paliashdr,
const vert_order_t *vo)
{
int count = vo->count;
const blended_vert_t *verts = vo->verts;
@ -222,7 +224,7 @@ GL_DrawAliasShadowTri (const transform_t *transform,
Standard shadow drawing
*/
static void
GL_DrawAliasShadow (const transform_t *transform, const aliashdr_t *paliashdr,
GL_DrawAliasShadow (transform_t transform, const aliashdr_t *paliashdr,
const vert_order_t *vo)
{
float height, lheight;
@ -270,9 +272,10 @@ GL_DrawAliasShadow (const transform_t *transform, const aliashdr_t *paliashdr,
}
static inline vert_order_t *
GL_GetAliasFrameVerts16 (aliashdr_t *paliashdr, entity_t *e)
GL_GetAliasFrameVerts16 (aliashdr_t *paliashdr, entity_t e)
{
animation_t *animation = &e->animation;
animation_t *animation = Ent_GetComponent (e.id, scene_animation,
r_refdef.scene->reg);
float blend;
int count, i;
trivertx16_t *verts;
@ -300,14 +303,14 @@ GL_GetAliasFrameVerts16 (aliashdr_t *paliashdr, entity_t *e)
if (blend == 0.0) {
verts = verts + e->animation.pose1 * count;
verts = verts + animation->pose1 * count;
} else if (blend == 1.0) {
verts = verts + e->animation.pose2 * count;
verts = verts + animation->pose2 * count;
} else {
trivertx16_t *verts1, *verts2;
verts1 = verts + e->animation.pose1 * count;
verts2 = verts + e->animation.pose2 * count;
verts1 = verts + animation->pose1 * count;
verts2 = verts + animation->pose2 * count;
for (i = 0, vo_v = vo->verts; i < count;
i++, vo_v++, verts1++, verts2++) {
@ -336,9 +339,10 @@ GL_GetAliasFrameVerts16 (aliashdr_t *paliashdr, entity_t *e)
}
static inline vert_order_t *
GL_GetAliasFrameVerts (aliashdr_t *paliashdr, entity_t *e)
GL_GetAliasFrameVerts (aliashdr_t *paliashdr, entity_t e)
{
animation_t *animation = &e->animation;
animation_t *animation = Ent_GetComponent (e.id, scene_animation,
r_refdef.scene->reg);
float blend;
int count, i;
trivertx_t *verts;
@ -364,14 +368,14 @@ GL_GetAliasFrameVerts (aliashdr_t *paliashdr, entity_t *e)
blend = 1.0;
if (blend == 0.0) {
verts = verts + e->animation.pose1 * count;
verts = verts + animation->pose1 * count;
} else if (blend == 1.0) {
verts = verts + e->animation.pose2 * count;
verts = verts + animation->pose2 * count;
} else {
trivertx_t *verts1, *verts2;
verts1 = verts + e->animation.pose1 * count;
verts2 = verts + e->animation.pose2 * count;
verts1 = verts + animation->pose1 * count;
verts2 = verts + animation->pose2 * count;
for (i = 0, vo_v = vo->verts; i < count;
i++, vo_v++, verts1++, verts2++) {
@ -400,7 +404,7 @@ GL_GetAliasFrameVerts (aliashdr_t *paliashdr, entity_t *e)
}
void
gl_R_DrawAliasModel (entity_t *e)
gl_R_DrawAliasModel (entity_t e)
{
float radius, minlight, d;
float position[4] = {0.0, 0.0, 0.0, 1.0},
@ -417,12 +421,15 @@ gl_R_DrawAliasModel (entity_t *e)
vec3_t dist, scale;
vec4f_t origin;
vert_order_t *vo;
transform_t transform = Entity_Transform (e);
renderer_t *renderer = Ent_GetComponent (e.id, scene_renderer,
r_refdef.scene->reg);
model = e->renderer.model;
model = renderer->model;
radius = model->radius;
origin = Transform_GetWorldPosition (e->transform);
VectorCopy (Transform_GetWorldScale (e->transform), scale);
origin = Transform_GetWorldPosition (transform);
VectorCopy (Transform_GetWorldScale (transform), scale);
//FIXME assumes uniform scale
if (scale[0] != 1.0) {
radius *= scale[0];
@ -431,12 +438,12 @@ gl_R_DrawAliasModel (entity_t *e)
return;
}
gl_modelalpha = e->renderer.colormod[3];
gl_modelalpha = renderer->colormod[3];
is_fullbright = (model->fullbright || e->renderer.fullbright);
minlight = max (model->min_light, e->renderer.min_light);
is_fullbright = (model->fullbright || renderer->fullbright);
minlight = max (model->min_light, renderer->min_light);
qfglColor4fv (e->renderer.colormod);
qfglColor4fv (renderer->colormod);
if (!is_fullbright) {
float lightadj;
@ -536,25 +543,25 @@ gl_R_DrawAliasModel (entity_t *e)
VectorScale (emission, 1.5 / d, emission);
}
emission[0] *= e->renderer.colormod[0];
emission[1] *= e->renderer.colormod[1];
emission[2] *= e->renderer.colormod[2];
emission[3] *= e->renderer.colormod[3];
emission[0] *= renderer->colormod[0];
emission[1] *= renderer->colormod[1];
emission[2] *= renderer->colormod[2];
emission[3] *= renderer->colormod[3];
qfglColor4fv (emission);
}
}
// locate the proper data
if (!(paliashdr = e->renderer.model->aliashdr)) {
paliashdr = Cache_Get (&e->renderer.model->cache);
if (!(paliashdr = renderer->model->aliashdr)) {
paliashdr = Cache_Get (&renderer->model->cache);
}
gl_ctx->alias_polys += paliashdr->mdl.numtris;
// if the model has a colorised/external skin, use it, otherwise use
// the skin embedded in the model data
if (e->renderer.skin && e->renderer.skin->texnum && !gl_nocolors) {
skin_t *skin = e->renderer.skin;
if (renderer->skin && renderer->skin->texnum && !gl_nocolors) {
skin_t *skin = renderer->skin;
texture = skin->texnum;
if (gl_fb_models) {
@ -562,9 +569,9 @@ gl_R_DrawAliasModel (entity_t *e)
}
} else {
maliasskindesc_t *skindesc;
animation_t *animation = &e->animation;
skindesc = R_AliasGetSkindesc (animation, e->renderer.skinnum,
animation_t *animation = Ent_GetComponent (e.id, scene_animation,
r_refdef.scene->reg);
skindesc = R_AliasGetSkindesc (animation, renderer->skinnum,
paliashdr);
texture = skindesc->texnum;
if (gl_fb_models && !is_fullbright) {
@ -586,7 +593,7 @@ gl_R_DrawAliasModel (entity_t *e)
// setup the transform
qfglPushMatrix ();
gl_R_RotateForEntity (e);
gl_R_RotateForEntity (Transform_GetWorldMatrixPtr (transform));
qfglTranslatef (paliashdr->mdl.scale_origin[0],
paliashdr->mdl.scale_origin[1],
@ -652,7 +659,7 @@ gl_R_DrawAliasModel (entity_t *e)
qfglDisable (GL_NORMALIZE);
}
qfglColor4fv (e->renderer.colormod);
qfglColor4fv (renderer->colormod);
qfglBindTexture (GL_TEXTURE_2D, fb_texture);
GL_DrawAliasFrameTri (vo);
@ -672,7 +679,7 @@ gl_R_DrawAliasModel (entity_t *e)
qfglDisable (GL_NORMALIZE);
}
qfglColor4fv (e->renderer.colormod);
qfglColor4fv (renderer->colormod);
qfglBindTexture (GL_TEXTURE_2D, fb_texture);
GL_DrawAliasFrame (vo);
@ -693,7 +700,7 @@ gl_R_DrawAliasModel (entity_t *e)
mat4f_t shadow_mat;
qfglPushMatrix ();
gl_R_RotateForEntity (e);
gl_R_RotateForEntity (Transform_GetWorldMatrixPtr (transform));
if (!gl_tess)
qfglDisable (GL_NORMALIZE);
@ -702,7 +709,7 @@ gl_R_DrawAliasModel (entity_t *e)
qfglDepthMask (GL_FALSE);
if (gl_modelalpha < 1.0) {
VectorBlend (e->renderer.colormod, dark, 0.5, color);
VectorBlend (renderer->colormod, dark, 0.5, color);
color[3] = gl_modelalpha * (model->shadow_alpha / 255.0);
qfglColor4fv (color);
} else {
@ -711,14 +718,14 @@ gl_R_DrawAliasModel (entity_t *e)
}
//FIXME fully vectorize
vec4f_t vec = { 0.707106781, 0, 0.707106781, 0 };
Transform_GetWorldMatrix (e->transform, shadow_mat);
Transform_GetWorldMatrix (transform, shadow_mat);
mat4ftranspose (shadow_mat, shadow_mat);
vec = m3vmulf (shadow_mat, vec);
VectorCopy (vec, shadevector);
if (vo->tex_coord)
GL_DrawAliasShadowTri (e->transform, paliashdr, vo);
GL_DrawAliasShadowTri (transform, paliashdr, vo);
else
GL_DrawAliasShadow (e->transform, paliashdr, vo);
GL_DrawAliasShadow (transform, paliashdr, vo);
qfglDepthMask (GL_TRUE);
qfglEnable (GL_TEXTURE_2D);
@ -734,7 +741,7 @@ gl_R_DrawAliasModel (entity_t *e)
qfglDisable (GL_LIGHT0 + used_lights);
}
if (!e->renderer.model->aliashdr) {
Cache_Release (&e->renderer.model->cache);
if (!renderer->model->aliashdr) {
Cache_Release (&renderer->model->cache);
}
}

View file

@ -49,7 +49,9 @@
#include "QF/GL/qf_iqm.h"
#include "QF/GL/qf_rmain.h"
#include "QF/GL/qf_vid.h"
#include "QF/scene/component.h"
#include "QF/scene/entity.h"
#include "QF/scene/scene.h"
#include "r_internal.h"
@ -86,21 +88,26 @@ gl_draw_iqm_frame (iqm_t *iqm, gliqm_t *gl, iqmframe_t *frame, iqmmesh *mesh)
}
void
gl_R_DrawIQMModel (entity_t *ent)
gl_R_DrawIQMModel (entity_t ent)
{
model_t *model = ent->renderer.model;
transform_t transform = Entity_Transform (ent);
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer,
r_refdef.scene->reg);
animation_t *animation = Ent_GetComponent (ent.id, scene_animation,
r_refdef.scene->reg);
model_t *model = renderer->model;
iqm_t *iqm = (iqm_t *) model->aliashdr;
gliqm_t *gl = (gliqm_t *) iqm->extra_data;
float blend;
iqmframe_t *frame;
int i;
blend = R_IQMGetLerpedFrames (ent, iqm);
frame = R_IQMBlendPalette (iqm, ent->animation.pose1, ent->animation.pose2,
blend = R_IQMGetLerpedFrames (animation, iqm);
frame = R_IQMBlendPalette (iqm, animation->pose1, animation->pose2,
blend, 0, gl->blend_palette, gl->palette_size);
qfglPushMatrix ();
gl_R_RotateForEntity (ent);
gl_R_RotateForEntity (Transform_GetWorldMatrixPtr (transform));
for (i = 0; i < iqm->num_meshes; i++) {
qfglBindTexture (GL_TEXTURE_2D, gl->textures[i]);

View file

@ -39,7 +39,9 @@
#include "QF/render.h"
#include "QF/sys.h"
#include "QF/scene/component.h"
#include "QF/scene/entity.h"
#include "QF/scene/scene.h"
#include "QF/GL/defines.h"
#include "QF/GL/funcs.h"
@ -53,31 +55,37 @@ static int sVAsize;
static int *sVAindices;
varray_t2f_c4ub_v3f_t *gl_spriteVertexArray;
void (*gl_R_DrawSpriteModel) (struct entity_s *ent);
void (*gl_R_DrawSpriteModel) (struct entity_s ent);
static void
R_DrawSpriteModel_f (entity_t *e)
R_DrawSpriteModel_f (entity_t e)
{
transform_t transform = Entity_Transform (e);
renderer_t *renderer = Ent_GetComponent (e.id, scene_renderer,
r_refdef.scene->reg);
animation_t *animation = Ent_GetComponent (e.id, scene_animation,
r_refdef.scene->reg);
float modelalpha, color[4];
vec4f_t cameravec = {};
vec4f_t up = {}, right = {}, pn = {};
vec4f_t origin, point;
msprite_t *sprite = e->renderer.model->cache.data;
msprite_t *sprite = renderer->model->cache.data;
mspriteframe_t *frame;
origin = Transform_GetWorldPosition (e->transform);
origin = Transform_GetWorldPosition (transform);
cameravec = r_refdef.frame.position - origin;
// don't bother culling, it's just a single polygon without a surface cache
frame = R_GetSpriteFrame (sprite, &e->animation);
frame = R_GetSpriteFrame (sprite, animation);
if (!R_BillboardFrame (e, sprite->type, cameravec, &up, &right, &pn)) {
if (!R_BillboardFrame (transform, sprite->type, cameravec,
&up, &right, &pn)) {
// the orientation is undefined so can't draw the sprite
return;
}
VectorCopy (e->renderer.colormod, color);
modelalpha = color[3] = e->renderer.colormod[3];
VectorCopy (renderer->colormod, color);
modelalpha = color[3] = renderer->colormod[3];
if (modelalpha < 1.0)
qfglDepthMask (GL_FALSE);
@ -112,27 +120,32 @@ R_DrawSpriteModel_f (entity_t *e)
}
static void
R_DrawSpriteModel_VA_f (entity_t *e)
R_DrawSpriteModel_VA_f (entity_t e)
{
transform_t transform = Entity_Transform (e);
renderer_t *renderer = Ent_GetComponent (e.id, scene_renderer,
r_refdef.scene->reg);
animation_t *animation = Ent_GetComponent (e.id, scene_animation,
r_refdef.scene->reg);
unsigned char modelalpha, color[4];
vec4f_t up = {}, right = {};
vec4f_t origin, point;
int i;
// unsigned int vacount;
msprite_t *psprite = e->renderer.model->cache.data;
msprite_t *psprite = renderer->model->cache.data;
mspriteframe_t *frame;
varray_t2f_c4ub_v3f_t *VA;
VA = gl_spriteVertexArray; // FIXME: Despair
// don't bother culling, it's just a single polygon without a surface cache
frame = R_GetSpriteFrame (psprite, &e->animation);
frame = R_GetSpriteFrame (psprite, animation);
qfglBindTexture (GL_TEXTURE_2D, frame->gl_texturenum); // FIXME: DESPAIR
if (psprite->type == SPR_ORIENTED) { // bullet marks on walls
up = Transform_Up (e->transform);
right = Transform_Right (e->transform);
up = Transform_Up (transform);
right = Transform_Right (transform);
} else if (psprite->type == SPR_VP_PARALLEL_UPRIGHT) {
up = (vec4f_t) { 0, 0, 1, 0 };
VectorCopy (r_refdef.frame.right, right);
@ -142,7 +155,7 @@ R_DrawSpriteModel_VA_f (entity_t *e)
}
for (i = 0; i < 4; i++) {
color[i] = e->renderer.colormod[i] * 255;
color[i] = renderer->colormod[i] * 255;
}
memcpy (VA[0].color, color, 4);
memcpy (VA[1].color, color, 4);
@ -153,7 +166,7 @@ R_DrawSpriteModel_VA_f (entity_t *e)
if (modelalpha < 255)
qfglDepthMask (GL_FALSE);
origin = Transform_GetWorldPosition (e->transform);
origin = Transform_GetWorldPosition (transform);
point = origin + frame->down * up + frame->left * right;
VectorCopy (point, VA[0].vertex);

View file

@ -39,7 +39,9 @@
#include <stdio.h>
#include <stdlib.h>
#include "QF/scene/component.h"
#include "QF/scene/entity.h"
#include "QF/scene/scene.h"
#include "QF/GL/defines.h"
#include "QF/GL/funcs.h"
@ -77,10 +79,8 @@ glrmain_init (void)
}
void
gl_R_RotateForEntity (entity_t *e)
gl_R_RotateForEntity (const vec4f_t *mat)
{
mat4f_t mat;
Transform_GetWorldMatrix (e->transform, mat);
qfglMultMatrixf ((vec_t*)&mat[0]);//FIXME
}
@ -113,7 +113,7 @@ gl_R_RenderEntities (entqueue_t *queue)
}
for (size_t i = 0; i < queue->ent_queues[mod_alias].size; i++) {
entity_t *ent = queue->ent_queues[mod_alias].a[i];
entity_t ent = queue->ent_queues[mod_alias].a[i];
gl_R_DrawAliasModel (ent);
}
qfglColor3ubv (color_white);
@ -142,7 +142,7 @@ gl_R_RenderEntities (entqueue_t *queue)
}
for (size_t i = 0; i < queue->ent_queues[mod_iqm].size; i++) { \
entity_t *ent = queue->ent_queues[mod_iqm].a[i]; \
entity_t ent = queue->ent_queues[mod_iqm].a[i]; \
gl_R_DrawIQMModel (ent);
}
qfglColor3ubv (color_white);
@ -152,7 +152,7 @@ gl_R_RenderEntities (entqueue_t *queue)
if (gl_va_capable)
qfglInterleavedArrays (GL_T2F_C4UB_V3F, 0, gl_spriteVertexArray);
for (size_t i = 0; i < queue->ent_queues[mod_sprite].size; i++) { \
entity_t *ent = queue->ent_queues[mod_sprite].a[i]; \
entity_t ent = queue->ent_queues[mod_sprite].a[i]; \
gl_R_DrawSpriteModel (ent);
}
qfglDisable (GL_ALPHA_TEST);
@ -161,11 +161,13 @@ gl_R_RenderEntities (entqueue_t *queue)
static void
R_DrawViewModel (void)
{
entity_t *ent = vr_data.view_model;
entity_t ent = vr_data.view_model;
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer,
r_refdef.scene->reg);
if (vr_data.inhibit_viewmodel
|| !r_drawviewmodel
|| !r_drawentities
|| !ent->renderer.model)
|| !renderer->model)
return;
// hack the depth range to prevent view model from poking into walls
@ -267,7 +269,7 @@ gl_R_RenderView (void)
gl_R_DrawWorld ();
gl_R_RenderDlights ();
if (vr_data.view_model) {
if (Entity_Valid (vr_data.view_model)) {
R_DrawViewModel ();
}

View file

@ -165,6 +165,7 @@ gl_R_NewScene (scene_t *scene)
for (int i = 0; i < 256; i++)
d_lightstylevalue[i] = 264; // normal light value
r_refdef.scene = scene;
r_refdef.worldmodel = scene->worldmodel;
brush = &scene->worldmodel->brush;

View file

@ -45,7 +45,9 @@
#include "QF/render.h"
#include "QF/sys.h"
#include "QF/scene/component.h"
#include "QF/scene/entity.h"
#include "QF/scene/scene.h"
#include "QF/GL/defines.h"
#include "QF/GL/funcs.h"
@ -67,8 +69,8 @@ static instsurf_t **sky_chain_tail;
typedef struct glbspctx_s {
mod_brush_t *brush;
entity_t *entity;
vec_t *transform;
animation_t *animation;
vec4f_t *transform;
float *color;
} glbspctx_t;
@ -192,7 +194,7 @@ R_RenderFullbrights (void)
for (sc = tex->tex_chain; sc; sc = sc->tex_chain) {
if (sc->transform) {
qfglPushMatrix ();
qfglLoadMatrixf (sc->transform);
qfglLoadMatrixf ((vec_t*)&sc->transform[0]);//FIXME
}
if (sc->color)
qfglColor4fv (sc->color);
@ -291,7 +293,7 @@ R_AddToLightmapChain (glbspctx_t *bctx, msurface_t *surf, instsurf_t *sc)
if ((surf->dlightframe == r_framecount) || surf->cached_dlight) {
dynamic:
if (r_dynamic) {
gl_R_BuildLightMap (bctx->entity->transform, bctx->brush, surf);
gl_R_BuildLightMap (bctx->transform, bctx->brush, surf);
}
}
}
@ -319,7 +321,7 @@ gl_R_DrawWaterSurfaces (void)
surf = s->surface;
if (s->transform) {
qfglPushMatrix ();
qfglLoadMatrixf (s->transform);
qfglLoadMatrixf ((vec_t*)&s->transform[0]);//FIXME
}
tex = surf->texinfo->texture->render;
if (i != tex->gl_texturenum) {
@ -374,7 +376,7 @@ DrawTextureChains (int disable_blend, int do_bind)
surf = s->surface;
if (s->transform) {
qfglPushMatrix ();
qfglLoadMatrixf (s->transform);
qfglLoadMatrixf ((vec_t*)&s->transform[0]);//FIXME
}
if (s->color && do_bind)
qfglColor4fv (s->color);
@ -397,7 +399,7 @@ DrawTextureChains (int disable_blend, int do_bind)
if (s->transform) {
qfglPushMatrix ();
qfglLoadMatrixf (s->transform);
qfglLoadMatrixf ((vec_t*)&s->transform[0]);//FIXME
}
if (s->color && do_bind)
qfglColor4fv (s->color);
@ -432,7 +434,7 @@ DrawTextureChains (int disable_blend, int do_bind)
for (s = tex->tex_chain; s; s = s->tex_chain) {
if (s->transform) {
qfglPushMatrix ();
qfglLoadMatrixf (s->transform);
qfglLoadMatrixf ((vec_t*)&s->transform[0]);//FIXME
}
R_RenderBrushPoly_1 (s->surface);
@ -484,7 +486,7 @@ chain_surface (glbspctx_t *bctx, msurface_t *surf)
if (!surf->texinfo->texture->anim_total)
tx = surf->texinfo->texture;
else
tx = R_TextureAnimation (bctx->entity, surf);
tx = R_TextureAnimation (bctx->animation, surf);
tex = tx->render;
sc = CHAIN_SURF_F2B (surf, tex->tex_chain);
@ -495,23 +497,28 @@ chain_surface (glbspctx_t *bctx, msurface_t *surf)
}
void
gl_R_DrawBrushModel (entity_t *e)
gl_R_DrawBrushModel (entity_t e)
{
float dot, radius;
transform_t transform = Entity_Transform (e);
renderer_t *renderer = Ent_GetComponent (e.id, scene_renderer,
r_refdef.scene->reg);
animation_t *animation = Ent_GetComponent (e.id, scene_animation,
r_refdef.scene->reg);
msurface_t *surf;
qboolean rotated;
vec3_t mins, maxs;
mat4f_t worldMatrix;
model_t *model = e->renderer.model;
model_t *model = renderer->model;
mod_brush_t *brush = &model->brush;
glbspctx_t bspctx = {
brush,
e,
e->renderer.full_transform,
e->renderer.colormod,
animation,
renderer->full_transform,
renderer->colormod,
};
Transform_GetWorldMatrix (e->transform, worldMatrix);
Transform_GetWorldMatrix (transform, worldMatrix);
if (worldMatrix[0][0] != 1 || worldMatrix[1][1] != 1
|| worldMatrix[2][2] != 1) {
rotated = true;
@ -562,8 +569,8 @@ gl_R_DrawBrushModel (entity_t *e)
}
qfglPushMatrix ();
gl_R_RotateForEntity (e);
qfglGetFloatv (GL_MODELVIEW_MATRIX, e->renderer.full_transform);
gl_R_RotateForEntity (Transform_GetWorldMatrixPtr (transform));
qfglGetFloatv (GL_MODELVIEW_MATRIX, (vec_t*)&renderer->full_transform[0]);
qfglPopMatrix ();
surf = &brush->surfaces[brush->firstmodelsurface];
@ -702,20 +709,17 @@ R_VisitWorldNodes (glbspctx_t *bctx)
void
gl_R_DrawWorld (void)
{
entity_t worldent;
animation_t animation = {};
glbspctx_t bctx = { };
memset (&worldent, 0, sizeof (worldent));
worldent.renderer.model = r_refdef.worldmodel;
sky_chain = 0;
sky_chain_tail = &sky_chain;
if (!gl_sky_clip) {
gl_R_DrawSky ();
}
bctx.brush = &worldent.renderer.model->brush;
bctx.entity = &worldent;
bctx.brush = &r_refdef.worldmodel->brush;
bctx.animation = &animation;
R_VisitWorldNodes (&bctx);
@ -723,7 +727,7 @@ gl_R_DrawWorld (void)
if (r_drawentities) {
for (size_t i = 0; i < r_ent_queue->ent_queues[mod_brush].size; i++) { \
entity_t *ent = r_ent_queue->ent_queues[mod_brush].a[i]; \
entity_t ent = r_ent_queue->ent_queues[mod_brush].a[i]; \
gl_R_DrawBrushModel (ent);
}
}

View file

@ -692,7 +692,7 @@ draw_black_sky_polys (const instsurf_t *sky_chain)
if (sc->transform) {
qfglPushMatrix ();
qfglLoadMatrixf (sc->transform);
qfglLoadMatrixf ((vec_t*)&sc->transform[0]);//FIXME
}
while (p) {
draw_poly (p);
@ -778,7 +778,7 @@ draw_z_sky_polys (const instsurf_t *sky_chain)
if (sc->transform) {
qfglPushMatrix ();
qfglLoadMatrixf (sc->transform);
qfglLoadMatrixf ((vec_t*)&sc->transform[0]);//FIXME
}
while (p) {
draw_poly (p);
@ -829,7 +829,7 @@ gl_R_DrawSkyChain (const instsurf_t *sky_chain)
if (sc->transform) {
qfglPushMatrix ();
qfglLoadMatrixf (sc->transform);
qfglLoadMatrixf ((vec_t*)&sc->transform[0]);//FIXME
}
while (p) {
int i;
@ -855,7 +855,7 @@ gl_R_DrawSkyChain (const instsurf_t *sky_chain)
if (sc->transform) {
qfglPushMatrix ();
qfglLoadMatrixf (sc->transform);
qfglLoadMatrixf ((vec_t*)&sc->transform[0]);//FIXME
}
while (p) {
int i;

View file

@ -44,7 +44,9 @@
#include "QF/skin.h"
#include "QF/sys.h"
#include "QF/scene/component.h"
#include "QF/scene/entity.h"
#include "QF/scene/scene.h"
#include "QF/GLSL/defines.h"
#include "QF/GLSL/funcs.h"
@ -149,7 +151,7 @@ glsl_R_InitAlias (void)
}
static void
calc_lighting (entity_t *ent, float *ambient, float *shadelight,
calc_lighting (entity_t ent, float *ambient, float *shadelight,
vec3_t lightvec)
{
unsigned i;
@ -157,13 +159,16 @@ calc_lighting (entity_t *ent, float *ambient, float *shadelight,
vec3_t dist;
vec4f_t entorigin;
int light;
transform_t transform = Entity_Transform (ent);
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer,
r_refdef.scene->reg);
entorigin = Transform_GetWorldPosition (ent->transform);
entorigin = Transform_GetWorldPosition (transform);
VectorSet ( -1, 0, 0, lightvec); //FIXME
light = R_LightPoint (&r_refdef.worldmodel->brush, entorigin);
*ambient = max (light, max (ent->renderer.model->min_light,
ent->renderer.min_light) * 128);
*ambient = max (light, max (renderer->model->min_light,
renderer->min_light) * 128);
*shadelight = *ambient;
for (i = 0; i < r_maxdlights; i++) {
@ -208,7 +213,7 @@ set_arrays (const shaderparam_t *vert, const shaderparam_t *norm,
}
//#define TETRAHEDRON
void
glsl_R_DrawAlias (entity_t *ent)
glsl_R_DrawAlias (entity_t ent)
{
#ifdef TETRAHEDRON
static aliasvrt_t debug_verts[] = {
@ -230,8 +235,6 @@ glsl_R_DrawAlias (entity_t *ent)
float shadelight;
float skin_size[2];
float blend;
animation_t *animation = &ent->animation;
model_t *model = ent->renderer.model;
aliashdr_t *hdr;
vec_t norm_mat[9];
int skin_tex;
@ -240,12 +243,18 @@ glsl_R_DrawAlias (entity_t *ent)
aliasvrt_t *pose2 = 0; // VBO's are null based
mat4f_t worldMatrix;
calc_lighting (ent, &ambient, &shadelight, lightvec);
transform_t transform = Entity_Transform (ent);
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer,
r_refdef.scene->reg);
animation_t *animation = Ent_GetComponent (ent.id, scene_animation,
r_refdef.scene->reg);
model_t *model = renderer->model;
if (!(hdr = model->aliashdr))
hdr = Cache_Get (&model->cache);
calc_lighting (ent, &ambient, &shadelight, lightvec);
Transform_GetWorldMatrix (ent->transform, worldMatrix);
Transform_GetWorldMatrix (transform, worldMatrix);
// we need only the rotation for normals.
VectorCopy (worldMatrix[0], norm_mat + 0);
VectorCopy (worldMatrix[1], norm_mat + 3);
@ -263,14 +272,14 @@ glsl_R_DrawAlias (entity_t *ent)
mmulf (mvp_mat, alias_vp, mvp_mat);
colormap = glsl_colormap;
if (ent->renderer.skin && ent->renderer.skin->auxtex)
colormap = ent->renderer.skin->auxtex;
if (ent->renderer.skin && ent->renderer.skin->texnum) {
skin_t *skin = ent->renderer.skin;
if (renderer->skin && renderer->skin->auxtex)
colormap = renderer->skin->auxtex;
if (renderer->skin && renderer->skin->texnum) {
skin_t *skin = renderer->skin;
skin_tex = skin->texnum;
} else {
maliasskindesc_t *skindesc;
skindesc = R_AliasGetSkindesc (animation, ent->renderer.skinnum, hdr);
skindesc = R_AliasGetSkindesc (animation, renderer->skinnum, hdr);
skin_tex = skindesc->texnum;
}
blend = R_AliasGetLerpedFrames (animation, hdr);

View file

@ -48,7 +48,9 @@
#include "QF/sys.h"
#include "QF/va.h"
#include "QF/scene/component.h"
#include "QF/scene/entity.h"
#include "QF/scene/scene.h"
#include "QF/GLSL/defines.h"
#include "QF/GLSL/funcs.h"
@ -238,8 +240,8 @@ static struct {
typedef struct glslbspctx_s {
mod_brush_t *brush;
entity_t *entity;
vec_t *transform;
animation_t *animation;
vec4f_t *transform;
float *color;
} glslbspctx_t;
@ -376,7 +378,7 @@ update_lightmap (glslbspctx_t *bctx, msurface_t *surf)
if ((surf->dlightframe == r_framecount) || surf->cached_dlight) {
dynamic:
if (r_dynamic)
glsl_R_BuildLightMap (bctx->entity->transform, bctx->brush, surf);
glsl_R_BuildLightMap (bctx->transform, bctx->brush, surf);
}
}
@ -397,7 +399,7 @@ chain_surface (glslbspctx_t *bctx, msurface_t *surf)
if (!surf->texinfo->texture->anim_total)
tx = surf->texinfo->texture;
else
tx = R_TextureAnimation (bctx->entity, surf);
tx = R_TextureAnimation (bctx->animation, surf);
tex = tx->render;
is = CHAIN_SURF_F2B (surf, tex->tex_chain);
@ -648,11 +650,16 @@ glsl_R_BuildDisplayLists (model_t **models, int num_models)
}
static void
R_DrawBrushModel (entity_t *e)
R_DrawBrushModel (entity_t e)
{
float dot, radius;
unsigned k;
model_t *model = e->renderer.model;
transform_t transform = Entity_Transform (e);
renderer_t *renderer = Ent_GetComponent (e.id, scene_renderer,
r_refdef.scene->reg);
animation_t *animation = Ent_GetComponent (e.id, scene_animation,
r_refdef.scene->reg);
model_t *model = renderer->model;
mod_brush_t *brush = &model->brush;
plane_t *plane;
msurface_t *surf;
@ -661,14 +668,14 @@ R_DrawBrushModel (entity_t *e)
vec4f_t org;
glslbspctx_t bctx = {
brush,
e,
e->renderer.full_transform,
e->renderer.colormod,
animation,
renderer->full_transform,
renderer->colormod,
};
mat4f_t mat;
Transform_GetWorldMatrix (e->transform, mat);
memcpy (e->renderer.full_transform, mat, sizeof (mat));//FIXME
Transform_GetWorldMatrix (transform, mat);
memcpy (renderer->full_transform, mat, sizeof (mat));//FIXME
if (mat[0][0] != 1 || mat[1][1] != 1 || mat[2][2] != 1) {
rotated = true;
radius = model->radius;
@ -846,7 +853,7 @@ static void
draw_elechain (elechain_t *ec, int matloc, int vertloc, int tlstloc,
int colloc)
{
mat4_t mat;
mat4f_t mat;
elements_t *el;
int count;
float *color;
@ -861,8 +868,8 @@ draw_elechain (elechain_t *ec, int matloc, int vertloc, int tlstloc,
}
}
if (ec->transform) {
Mat4Mult ((vec_t*)&bsp_vp[0], ec->transform, mat);//FIXME
qfeglUniformMatrix4fv (matloc, 1, false, mat);
mmulf (mat, bsp_vp, ec->transform);
qfeglUniformMatrix4fv (matloc, 1, false, (vec_t*)&mat[0]);//FIXME
} else {
qfeglUniformMatrix4fv (matloc, 1, false, (vec_t*)&bsp_vp[0]);//FIXME
}
@ -1140,22 +1147,19 @@ build_tex_elechain (glsltex_t *tex)
void
glsl_R_DrawWorld (void)
{
entity_t worldent;
animation_t animation = {};
glslbspctx_t bctx = { };
int i;
clear_texture_chains (); // do this first for water and skys
memset (&worldent, 0, sizeof (worldent));
worldent.renderer.model = r_refdef.worldmodel;
bctx.brush = &worldent.renderer.model->brush;
bctx.entity = &worldent;
bctx.brush = &r_refdef.worldmodel->brush;
bctx.animation = &animation;
R_VisitWorldNodes (&bctx);
if (r_drawentities) {
for (size_t i = 0; i < r_ent_queue->ent_queues[mod_brush].size; i++) {
entity_t *ent = r_ent_queue->ent_queues[mod_brush].a[i];
entity_t ent = r_ent_queue->ent_queues[mod_brush].a[i];
R_DrawBrushModel (ent);
}
}

View file

@ -44,7 +44,9 @@
#include "QF/skin.h"
#include "QF/sys.h"
#include "QF/scene/component.h"
#include "QF/scene/entity.h"
#include "QF/scene/scene.h"
#include "QF/GLSL/defines.h"
#include "QF/GLSL/funcs.h"
@ -202,10 +204,15 @@ set_arrays (iqm_t *iqm)
}
void
glsl_R_DrawIQM (entity_t *ent)
glsl_R_DrawIQM (entity_t ent)
{
transform_t transform = Entity_Transform (ent);
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer,
r_refdef.scene->reg);
animation_t *animation = Ent_GetComponent (ent.id, scene_animation,
r_refdef.scene->reg);
static quat_t color = { 1, 1, 1, 1};
model_t *model = ent->renderer.model;
model_t *model = renderer->model;
iqm_t *iqm = (iqm_t *) model->aliashdr;
glsliqm_t *glsl = (glsliqm_t *) iqm->extra_data;
dlight_t *lights[MAX_IQM_LIGHTS];
@ -218,7 +225,7 @@ glsl_R_DrawIQM (entity_t *ent)
// we need only the rotation for normals.
mat4f_t mat;
Transform_GetWorldMatrix (ent->transform, mat);
Transform_GetWorldMatrix (transform, mat);
VectorCopy (mat[0], norm_mat + 0);
VectorCopy (mat[1], norm_mat + 3);
VectorCopy (mat[2], norm_mat + 6);
@ -229,8 +236,8 @@ glsl_R_DrawIQM (entity_t *ent)
VectorScale (ambientcolor, 1/255.0, ambientcolor);
R_FindNearLights (entorigin, MAX_IQM_LIGHTS, lights);
blend = R_IQMGetLerpedFrames (ent, iqm);
frame = R_IQMBlendFrames (iqm, ent->animation.pose1, ent->animation.pose2,
blend = R_IQMGetLerpedFrames (animation, iqm);
frame = R_IQMBlendFrames (iqm, animation->pose1, animation->pose2,
blend, 0);
qfeglUniform3fv (iqm_shader.ambient.location, 1, ambientcolor);

View file

@ -60,11 +60,11 @@ static scrap_t *light_scrap;
static unsigned *blocklights;
static int bl_extents[2];
void (*glsl_R_BuildLightMap) (const transform_t *transform, mod_brush_t *brush,
void (*glsl_R_BuildLightMap) (const vec4f_t *transform, mod_brush_t *brush,
msurface_t *surf);
static void
R_AddDynamicLights_1 (const transform_t *transform, msurface_t *surf)
R_AddDynamicLights_1 (const vec4f_t *transform, msurface_t *surf)
{
unsigned lnum;
int sd, td;
@ -81,7 +81,7 @@ R_AddDynamicLights_1 (const transform_t *transform, msurface_t *surf)
if (transform) {
//FIXME give world entity a transform
entorigin = Transform_GetWorldPosition (transform);
entorigin = transform[3];
}
for (lnum = 0; lnum < r_maxdlights; lnum++) {
@ -126,7 +126,7 @@ R_AddDynamicLights_1 (const transform_t *transform, msurface_t *surf)
}
static void
R_BuildLightMap_1 (const transform_t *transform, mod_brush_t *brush,
R_BuildLightMap_1 (const vec4f_t *transform, mod_brush_t *brush,
msurface_t *surf)
{
int smax, tmax, size;

View file

@ -45,6 +45,7 @@
#include "QF/screen.h"
#include "QF/sys.h"
#include "QF/scene/component.h"
#include "QF/scene/entity.h"
#include "QF/scene/scene.h"
@ -97,7 +98,7 @@ glsl_R_RenderEntities (entqueue_t *queue)
begun = 0; \
for (size_t i = 0; i < queue->ent_queues[mod_##type_name].size; \
i++) { \
entity_t *ent = queue->ent_queues[mod_##type_name].a[i]; \
entity_t ent = queue->ent_queues[mod_##type_name].a[i]; \
if (!begun) { \
glsl_R_##Type##Begin (); \
begun = 1; \
@ -116,11 +117,13 @@ glsl_R_RenderEntities (entqueue_t *queue)
static void
R_DrawViewModel (void)
{
entity_t *ent = vr_data.view_model;
entity_t ent = vr_data.view_model;
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer,
r_refdef.scene->reg);
if (vr_data.inhibit_viewmodel
|| !r_drawviewmodel
|| !r_drawentities
|| !ent->renderer.model)
|| !renderer->model)
return;
// hack the depth range to prevent view model from poking into walls
@ -143,7 +146,7 @@ glsl_R_RenderView (void)
R_SetupView ();
glsl_R_DrawWorld ();
glsl_R_DrawSky ();
if (vr_data.view_model) {
if (Entity_Valid (vr_data.view_model)) {
R_DrawViewModel ();
}
}
@ -196,6 +199,7 @@ glsl_R_NewScene (scene_t *scene)
for (i = 0; i < 256; i++)
d_lightstylevalue[i] = 264; // normal light value
r_refdef.scene = scene;
r_refdef.worldmodel = scene->worldmodel;
// Force a vis update

View file

@ -45,7 +45,9 @@
#include "QF/sys.h"
#include "QF/vid.h"
#include "QF/scene/component.h"
#include "QF/scene/entity.h"
#include "QF/scene/scene.h"
#include "QF/GLSL/defines.h"
#include "QF/GLSL/funcs.h"
@ -128,10 +130,11 @@ glsl_R_InitSprites (void)
}
static void
R_GetSpriteFrames (entity_t *ent, msprite_t *sprite, mspriteframe_t **frame1,
R_GetSpriteFrames (entity_t ent, msprite_t *sprite, mspriteframe_t **frame1,
mspriteframe_t **frame2, float *blend)
{
animation_t *animation = &ent->animation;
animation_t *animation = Ent_GetComponent (ent.id, scene_animation,
r_refdef.scene->reg);
int framenum = animation->frame;
int pose;
int i, numframes;
@ -206,9 +209,12 @@ make_quad (mspriteframe_t *frame, vec4f_t origin, vec4f_t sright, vec4f_t sup, f
}
void
glsl_R_DrawSprite (entity_t *ent)
glsl_R_DrawSprite (entity_t ent)
{
msprite_t *sprite = (msprite_t *) ent->renderer.model->cache.data;
transform_t transform = Entity_Transform (ent);
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer,
r_refdef.scene->reg);
msprite_t *sprite = (msprite_t *) renderer->model->cache.data;
mspriteframe_t *frame1, *frame2;
float blend;
vec4f_t cameravec = {};
@ -224,10 +230,11 @@ glsl_R_DrawSprite (entity_t *ent)
{ 0, 1, 0, 1 },
};
vec4f_t origin = Transform_GetWorldPosition (ent->transform);
vec4f_t origin = Transform_GetWorldPosition (transform);
cameravec = r_refdef.frame.position - origin;
if (!R_BillboardFrame (ent, sprite->type, cameravec, &sup, &sright, &spn)) {
if (!R_BillboardFrame (transform, sprite->type, cameravec,
&sup, &sright, &spn)) {
// the orientation is undefined so can't draw the sprite
return;
}

View file

@ -46,7 +46,7 @@
int
R_BillboardFrame (entity_t *ent, int orientation, vec4f_t cameravec,
R_BillboardFrame (transform_t transform, int orientation, vec4f_t cameravec,
vec4f_t *bbup, vec4f_t *bbright, vec4f_t *bbfwd)
{
vec4f_t tvec;
@ -90,7 +90,7 @@ R_BillboardFrame (entity_t *ent, int orientation, vec4f_t cameravec,
// The billboard's orientation is fully specified by the
// entity's orientation.
mat4f_t mat;
Transform_GetWorldMatrix (ent->transform, mat);
Transform_GetWorldMatrix (transform, mat);
*bbfwd = mat[0];
*bbright = mat[1];
*bbup = mat[2];
@ -102,7 +102,7 @@ R_BillboardFrame (entity_t *ent, int orientation, vec4f_t cameravec,
// the entity's local rotation.
mat4f_t entmat;
mat4f_t spmat;
Transform_GetLocalMatrix (ent->transform, entmat);
Transform_GetLocalMatrix (transform, entmat);
// FIXME needs proper testing (need to find, make, or fake a
// parallel oriented sprite)
mmulf (spmat, r_refdef.camera, entmat);

View file

@ -103,12 +103,12 @@ R_MarkLeaves (mleaf_t *viewleaf, int *node_visframes, int *leaf_visframes,
Returns the proper texture for a given time and base texture
*/
texture_t *
R_TextureAnimation (const entity_t *entity, msurface_t *surf)
R_TextureAnimation (const animation_t *animation, msurface_t *surf)
{
texture_t *base = surf->texinfo->texture;
int count, relative;
if (entity->animation.frame) {
if (animation->frame) {
if (base->alternate_anims)
base = base->alternate_anims;
}

View file

@ -101,11 +101,12 @@ R_ClearEfrags (void)
Call when removing an object from the world or moving it to another position
*/
void
R_RemoveEfrags (entity_t *ent)
R_RemoveEfrags (entity_t ent)
{
efrag_t *ef, *old, *walk, **prev;
visibility_t *vis = Ent_GetComponent (ent.id, scene_visibility, ent.reg);
ef = ent->visibility.efrag;
ef = vis->efrag;
while (ef) {
prev = &ef->leaf->efrags;
@ -128,12 +129,12 @@ R_RemoveEfrags (entity_t *ent)
r_free_efrags = old;
}
ent->visibility.efrag = 0;
vis->efrag = 0;
}
static void
R_SplitEntityOnNode (mod_brush_t *brush, entity_t *ent,
vec3_t emins, vec3_t emaxs)
R_SplitEntityOnNode (mod_brush_t *brush, entity_t ent, uint32_t queue,
visibility_t *visibility, vec3_t emins, vec3_t emaxs)
{
efrag_t *ef;
plane_t *splitplane;
@ -146,7 +147,7 @@ R_SplitEntityOnNode (mod_brush_t *brush, entity_t *ent,
node_stack = alloca ((brush->depth + 2) * sizeof (mnode_t *));
node_ptr = node_stack;
lastlink = &ent->visibility.efrag;
lastlink = &visibility->efrag;
*node_ptr++ = brush->numnodes;
@ -154,8 +155,8 @@ R_SplitEntityOnNode (mod_brush_t *brush, entity_t *ent,
while (node_id != (int) brush->numnodes) {
// add an efrag if the node is a leaf
if (__builtin_expect (node_id < 0, 0)) {
if (ent->visibility.topnode_id == -1) {
ent->visibility.topnode_id = node_id;
if (visibility->topnode_id == -1) {
visibility->topnode_id = node_id;
}
leaf = brush->leafs + ~node_id;
@ -164,6 +165,7 @@ R_SplitEntityOnNode (mod_brush_t *brush, entity_t *ent,
// add the link to the chain of links on the entity
ef->entity = ent;
ef->queue_num = queue;
*lastlink = ef;
lastlink = &ef->entnext;
@ -182,8 +184,8 @@ R_SplitEntityOnNode (mod_brush_t *brush, entity_t *ent,
if (sides == 3) {
// split on this plane
// if this is the first splitter of this bmodel, remember it
if (ent->visibility.topnode_id == -1) {
ent->visibility.topnode_id = node_id;
if (visibility->topnode_id == -1) {
visibility->topnode_id = node_id;
}
}
// recurse down the contacted sides
@ -202,45 +204,34 @@ R_SplitEntityOnNode (mod_brush_t *brush, entity_t *ent,
}
void
R_AddEfrags (mod_brush_t *brush, entity_t *ent)
R_AddEfrags (mod_brush_t *brush, entity_t ent)
{
model_t *entmodel;
vec3_t emins, emaxs;
transform_t transform = Entity_Transform (ent);
renderer_t *rend = Ent_GetComponent (ent.id, scene_renderer, ent.reg);
visibility_t *vis = Ent_GetComponent (ent.id, scene_visibility, ent.reg);
if (!ent->renderer.model) {
if (!rend->model) {
return;
}
entmodel = ent->renderer.model;
entmodel = rend->model;
vec4f_t org = Transform_GetWorldPosition (ent->transform);
vec4f_t org = Transform_GetWorldPosition (transform);
VectorAdd (org, entmodel->mins, emins);
VectorAdd (org, entmodel->maxs, emaxs);
ent->visibility.topnode_id = -1; // leaf 0 (solid space)
R_SplitEntityOnNode (brush, ent, emins, emaxs);
vis->topnode_id = -1; // leaf 0 (solid space)
R_SplitEntityOnNode (brush, ent, rend->model->type, vis, emins, emaxs);
}
void
R_StoreEfrags (const efrag_t *efrag)
{
entity_t *ent;
model_t *model;
while (efrag) {
ent = efrag->entity;
model = ent->renderer.model;
switch (model->type) {
case mod_alias:
case mod_brush:
case mod_sprite:
case mod_iqm:
EntQueue_AddEntity (r_ent_queue, ent, model->type);
break;
default:
break;
}
entity_t ent = efrag->entity;
EntQueue_AddEntity (r_ent_queue, ent, efrag->queue_num);
efrag = efrag->leafnext;
}
}

View file

@ -48,10 +48,9 @@
#include "r_internal.h"
float
R_IQMGetLerpedFrames (entity_t *ent, iqm_t *iqm)
R_IQMGetLerpedFrames (animation_t *animation, iqm_t *iqm)
{
animation_t *animation = &ent->animation;
int frame = ent->animation.frame;
int frame = animation->frame;
float time, fullinterval;
iqmanim *anim;
@ -64,7 +63,7 @@ R_IQMGetLerpedFrames (entity_t *ent, iqm_t *iqm)
}
anim = &iqm->anims[frame];
fullinterval = anim->num_frames / anim->framerate;
time = vr_data.realtime + ent->animation.syncbase;
time = vr_data.realtime + animation->syncbase;
time -= ((int) (time / fullinterval)) * fullinterval;
frame = (int) (time * anim->framerate) + anim->first_frame;
return R_EntityBlend (animation, frame, 1.0 / anim->framerate);

View file

@ -226,7 +226,7 @@ render_side (int side)
}
void
SCR_UpdateScreen (transform_t *camera, double realtime, SCR_Func *scr_funcs)
SCR_UpdateScreen (transform_t camera, double realtime, SCR_Func *scr_funcs)
{
if (scr_skipupdate || !scr_initialized) {
return;
@ -241,7 +241,7 @@ SCR_UpdateScreen (transform_t *camera, double realtime, SCR_Func *scr_funcs)
}
refdef_t *refdef = r_data->refdef;
if (camera) {
if (Transform_Valid (camera)) {
Transform_GetWorldMatrix (camera, refdef->camera);
Transform_GetWorldInverse (camera, refdef->camera_inverse);
} else {

View file

@ -31,7 +31,9 @@
#include "QF/cvar.h"
#include "QF/render.h"
#include "QF/scene/component.h"
#include "QF/scene/entity.h"
#include "QF/scene/scene.h"
#include "d_local.h"
#include "r_internal.h"
@ -143,6 +145,19 @@ D_CalcGradients (msurface_t *pface)
bbextentt = ((pface->extents[1] << 16) >> miplevel) - 1;
}
static void
transform_submodel_poly (surf_t *s)
{
// FIXME: we don't want to do all this for every polygon!
// TODO: store once at start of frame
transform_t transform = Entity_Transform (s->entity);
vec4f_t local_modelorg = r_refdef.frame.position -
Transform_GetWorldPosition (transform);
TransformVector ((vec_t*)&local_modelorg, transformed_modelorg);//FIXME
R_RotateBmodel (transform); // FIXME: don't mess with the
// frustum, make entity passed in
}
void
D_DrawSurfaces (void)
@ -151,7 +166,6 @@ D_DrawSurfaces (void)
msurface_t *pface;
surfcache_t *pcurrentcache;
vec3_t world_transformed_modelorg;
vec4f_t local_modelorg;
TransformVector (modelorg, transformed_modelorg);
VectorCopy (transformed_modelorg, world_transformed_modelorg);
@ -204,16 +218,7 @@ D_DrawSurfaces (void)
cachewidth = 64;
if (s->insubmodel) {
// FIXME: we don't want to do all this for every polygon!
// TODO: store once at start of frame
transform_t *transform = s->entity->transform;
transform = s->entity->transform;
local_modelorg = r_refdef.frame.position -
Transform_GetWorldPosition (transform);
TransformVector ((vec_t*)&local_modelorg, transformed_modelorg);//FIXME
R_RotateBmodel (transform); // FIXME: don't mess with the
// frustum, make entity passed in
transform_submodel_poly (s);
}
D_CalcGradients (pface);
@ -236,15 +241,7 @@ D_DrawSurfaces (void)
}
} else {
if (s->insubmodel) {
// FIXME: we don't want to do all this for every polygon!
// TODO: store once at start of frame
transform_t *transform = s->entity->transform;
local_modelorg = r_refdef.frame.position -
Transform_GetWorldPosition (transform);
TransformVector ((vec_t*)&local_modelorg, transformed_modelorg);//FIXME
R_RotateBmodel (transform); // FIXME: don't mess with the
// frustum, make entity passed in
transform_submodel_poly (s);
}
pface = s->data;

View file

@ -33,7 +33,9 @@
#include "QF/qargs.h"
#include "QF/render.h"
#include "QF/sys.h"
#include "QF/scene/component.h"
#include "QF/scene/entity.h"
#include "QF/scene/scene.h"
#include "compat.h"
#include "d_local.h"
@ -225,12 +227,14 @@ D_SCDump (void)
#endif
surfcache_t *
D_CacheSurface (entity_t *ent, msurface_t *surface, int miplevel)
D_CacheSurface (entity_t ent, msurface_t *surface, int miplevel)
{
surfcache_t *cache;
animation_t *animation = Ent_GetComponent (ent.id, scene_animation, r_refdef.scene->reg);
transform_t transform = Entity_Transform (ent);
// if the surface is animating or flashing, flush the cache
r_drawsurf.texture = R_TextureAnimation (ent, surface);
r_drawsurf.texture = R_TextureAnimation (animation, surface);
r_drawsurf.lightadj[0] = d_lightstylevalue[surface->styles[0]];
r_drawsurf.lightadj[1] = d_lightstylevalue[surface->styles[1]];
r_drawsurf.lightadj[2] = d_lightstylevalue[surface->styles[2]];
@ -281,7 +285,7 @@ D_CacheSurface (entity_t *ent, msurface_t *surface, int miplevel)
r_drawsurf.surf = surface;
c_surf++;
R_DrawSurface (ent->transform);
R_DrawSurface (transform);
return surface->cachespots[miplevel];
}

View file

@ -36,7 +36,9 @@
#include "QF/skin.h"
#include "QF/sys.h"
#include "QF/scene/component.h"
#include "QF/scene/entity.h"
#include "QF/scene/scene.h"
#include "d_ifacea.h"
#include "r_internal.h"
@ -83,10 +85,10 @@ static aedge_t aedges[12] = {
{0, 5}, {1, 4}, {2, 7}, {3, 6}
};
static void R_AliasSetUpTransform (entity_t *ent, int trivial_accept);
static void R_AliasSetUpTransform (entity_t ent, int trivial_accept);
qboolean
R_AliasCheckBBox (entity_t *ent)
R_AliasCheckBBox (entity_t ent)
{
int i, flags, frame, numv;
aliashdr_t *pahdr;
@ -97,10 +99,16 @@ R_AliasCheckBBox (entity_t *ent)
qboolean zclipped, zfullyclipped;
unsigned int anyclip, allclip;
int minz;
visibility_t *visibility = Ent_GetComponent (ent.id, scene_visibility,
r_refdef.scene->reg);
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer,
r_refdef.scene->reg);
animation_t *animation = Ent_GetComponent (ent.id, scene_animation,
r_refdef.scene->reg);
// expand, rotate, and translate points into worldspace
ent->visibility.trivial_accept = 0;
pmodel = ent->renderer.model;
visibility->trivial_accept = 0;
pmodel = renderer->model;
if (!(pahdr = pmodel->aliashdr))
pahdr = Cache_Get (&pmodel->cache);
pmdl = (mdl_t *) ((byte *) pahdr + pahdr->model);
@ -108,7 +116,7 @@ R_AliasCheckBBox (entity_t *ent)
R_AliasSetUpTransform (ent, 0);
// construct the base bounding box for this frame
frame = ent->animation.frame;
frame = animation->frame;
// TODO: don't repeat this check when drawing?
if ((frame >= pmdl->numframes) || (frame < 0)) {
Sys_MaskPrintf (SYS_dev, "No such frame %d %s\n", frame, pmodel->path);
@ -223,11 +231,11 @@ R_AliasCheckBBox (entity_t *ent)
return false; // trivial reject off one side
}
ent->visibility.trivial_accept = !anyclip & !zclipped;
visibility->trivial_accept = !anyclip & !zclipped;
if (ent->visibility.trivial_accept) {
if (visibility->trivial_accept) {
if (minz > (r_aliastransition + (pmdl->size * r_resfudge))) {
ent->visibility.trivial_accept |= 2;
visibility->trivial_accept |= 2;
}
}
@ -354,13 +362,14 @@ R_AliasPreparePoints (void)
}
static void
R_AliasSetUpTransform (entity_t *ent, int trivial_accept)
R_AliasSetUpTransform (entity_t ent, int trivial_accept)
{
int i;
float rotationmatrix[3][4];
mat4f_t mat;
transform_t transform = Entity_Transform (ent);
Transform_GetWorldMatrix (ent->transform, mat);
mat4f_t mat;
Transform_GetWorldMatrix (transform, mat);
VectorCopy (mat[0], alias_forward);
VectorCopy (mat[1], alias_left);
VectorCopy (mat[2], alias_up);
@ -520,18 +529,22 @@ R_AliasPrepareUnclippedPoints (void)
}
static void
R_AliasSetupSkin (entity_t *ent)
R_AliasSetupSkin (entity_t ent)
{
int skinnum;
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer,
r_refdef.scene->reg);
skinnum = ent->renderer.skinnum;
skinnum = renderer->skinnum;
if ((skinnum >= pmdl->numskins) || (skinnum < 0)) {
Sys_MaskPrintf (SYS_dev, "R_AliasSetupSkin: no such skin # %d\n",
skinnum);
skinnum = 0;
}
pskindesc = R_AliasGetSkindesc (&ent->animation, skinnum, paliashdr);
animation_t *animation = Ent_GetComponent (ent.id, scene_animation,
r_refdef.scene->reg);
pskindesc = R_AliasGetSkindesc (animation, skinnum, paliashdr);
a_skinwidth = pmdl->skinwidth;
@ -541,16 +554,16 @@ R_AliasSetupSkin (entity_t *ent)
r_affinetridesc.skinheight = pmdl->skinheight;
acolormap = r_colormap;
if (ent->renderer.skin) {
if (renderer->skin) {
tex_t *base;
base = ent->renderer.skin->texels;
base = renderer->skin->texels;
if (base) {
r_affinetridesc.pskin = base->data;
r_affinetridesc.skinwidth = base->width;
r_affinetridesc.skinheight = base->height;
}
acolormap = ent->renderer.skin->colormap;
acolormap = renderer->skin->colormap;
}
}
@ -589,25 +602,31 @@ R_AliasSetupLighting (alight_t *lighting)
set r_apverts
*/
static void
R_AliasSetupFrame (entity_t *ent)
R_AliasSetupFrame (entity_t ent)
{
maliasframedesc_t *frame;
frame = R_AliasGetFramedesc (&ent->animation, paliashdr);
animation_t *animation = Ent_GetComponent (ent.id, scene_animation,
r_refdef.scene->reg);
frame = R_AliasGetFramedesc (animation, paliashdr);
r_apverts = (trivertx_t *) ((byte *) paliashdr + frame->frame);
}
void
R_AliasDrawModel (entity_t *ent, alight_t *lighting)
R_AliasDrawModel (entity_t ent, alight_t *lighting)
{
int size;
finalvert_t *finalverts;
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer,
r_refdef.scene->reg);
visibility_t *visibility = Ent_GetComponent (ent.id, scene_visibility,
r_refdef.scene->reg);
r_amodels_drawn++;
if (!(paliashdr = ent->renderer.model->aliashdr))
paliashdr = Cache_Get (&ent->renderer.model->cache);
if (!(paliashdr = renderer->model->aliashdr))
paliashdr = Cache_Get (&renderer->model->cache);
pmdl = (mdl_t *) ((byte *) paliashdr + paliashdr->model);
size = (CACHE_SIZE - 1)
@ -623,11 +642,11 @@ R_AliasDrawModel (entity_t *ent, alight_t *lighting)
pauxverts = (auxvert_t *) &pfinalverts[pmdl->numverts + 1];
R_AliasSetupSkin (ent);
R_AliasSetUpTransform (ent, ent->visibility.trivial_accept);
R_AliasSetUpTransform (ent, visibility->trivial_accept);
R_AliasSetupLighting (lighting);
R_AliasSetupFrame (ent);
r_affinetridesc.drawtype = ((ent->visibility.trivial_accept == 3)
r_affinetridesc.drawtype = ((visibility->trivial_accept == 3)
&& r_recursiveaffinetriangles);
if (!acolormap)
@ -641,18 +660,19 @@ R_AliasDrawModel (entity_t *ent, alight_t *lighting)
#endif
}
if (ent != vr_data.view_model)
//FIXME depth hack
if (ent.id != vr_data.view_model.id)
ziscale = (float) 0x8000 *(float) 0x10000;
else
ziscale = (float) 0x8000 *(float) 0x10000 *3.0;
if (ent->visibility.trivial_accept && pmdl->ident != HEADER_MDL16) {
if (visibility->trivial_accept && pmdl->ident != HEADER_MDL16) {
R_AliasPrepareUnclippedPoints ();
} else {
R_AliasPreparePoints ();
}
if (!ent->renderer.model->aliashdr) {
Cache_Release (&ent->renderer.model->cache);
if (!renderer->model->aliashdr) {
Cache_Release (&renderer->model->cache);
}
}

View file

@ -36,13 +36,15 @@
#include "QF/render.h"
#include "QF/sys.h"
#include "QF/scene/component.h"
#include "QF/scene/entity.h"
#include "QF/scene/scene.h"
#include "r_internal.h"
typedef struct glbspctx_s {
mod_brush_t *brush;
entity_t *entity;
entity_t entity;
} swbspctx_t;
// current entity info
@ -83,7 +85,7 @@ R_EntityRotate (vec3_t vec)
void
R_RotateBmodel (transform_t *transform)
R_RotateBmodel (transform_t transform)
{
mat4f_t mat;
Transform_GetWorldMatrix (transform, mat);
@ -102,7 +104,7 @@ R_RotateBmodel (transform_t *transform)
static void
R_RecursiveClipBPoly (entity_t *ent, bedge_t *pedges, mnode_t *pnode,
R_RecursiveClipBPoly (entity_t ent, bedge_t *pedges, mnode_t *pnode,
msurface_t *psurf)
{
bedge_t *psideedges[2], *pnextedge, *ptedge;
@ -250,7 +252,7 @@ R_RecursiveClipBPoly (entity_t *ent, bedge_t *pedges, mnode_t *pnode,
void
R_DrawSolidClippedSubmodelPolygons (entity_t *ent, model_t *model,
R_DrawSolidClippedSubmodelPolygons (entity_t ent, model_t *model,
mnode_t *topnode)
{
int i, j, lindex;
@ -321,7 +323,7 @@ R_DrawSolidClippedSubmodelPolygons (entity_t *ent, model_t *model,
void
R_DrawSubmodelPolygons (entity_t *ent, model_t *model, int clipflags,
R_DrawSubmodelPolygons (entity_t ent, model_t *model, int clipflags,
mleaf_t *topleaf)
{
int i;
@ -377,8 +379,8 @@ visit_node (swbspctx_t *bctx, mnode_t *node, int side, int clipflags)
{
int c;
msurface_t *surf;
entity_t *ent = bctx->entity;
mod_brush_t *brush = &ent->renderer.model->brush;
entity_t ent = bctx->entity;
mod_brush_t *brush = bctx->brush;
// sneaky hack for side = side ? SURF_PLANEBACK : 0;
side = (~side + 1) & SURF_PLANEBACK;
@ -474,7 +476,7 @@ R_VisitWorldNodes (swbspctx_t *bctx, int clipflags)
int front;
int side, cf;
int node_id;
mod_brush_t *brush = &bctx->entity->renderer.model->brush;
mod_brush_t *brush = bctx->brush;
// +2 for paranoia
node_stack = alloca ((brush->depth + 2) * sizeof (rstack_t));
@ -531,14 +533,12 @@ R_RenderWorld (void)
{
int i;
btofpoly_t btofpolys[MAX_BTOFPOLYS];
static entity_t worldent = {};
entity_t *ent = &worldent;
entity_t ent = nullentity;
mod_brush_t *brush = &r_refdef.worldmodel->brush;
swbspctx_t bspctx = {
brush,
ent,
};
worldent.renderer.model = r_refdef.worldmodel;
pbtofpolys = btofpolys;

View file

@ -29,7 +29,9 @@
#endif
#include "QF/render.h"
#include "QF/scene/component.h"
#include "QF/scene/entity.h"
#include "QF/scene/scene.h"
#include "r_internal.h"
@ -345,7 +347,7 @@ R_EmitCachedEdge (void)
void
R_RenderFace (entity_t *ent, msurface_t *fa, int clipflags)
R_RenderFace (entity_t ent, msurface_t *fa, int clipflags)
{
int i, lindex;
unsigned int mask;
@ -354,7 +356,9 @@ R_RenderFace (entity_t *ent, msurface_t *fa, int clipflags)
vec3_t p_normal;
medge_t *pedges, tedge;
clipplane_t *pclip;
mod_brush_t *brush = &ent->renderer.model->brush;
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer,
r_refdef.scene->reg);
mod_brush_t *brush = &renderer->model->brush;
// skip out if no more surfs
if ((surface_p) >= surf_max) {
@ -511,7 +515,7 @@ R_RenderFace (entity_t *ent, msurface_t *fa, int clipflags)
void
R_RenderBmodelFace (entity_t *ent, bedge_t *pedges, msurface_t *psurf)
R_RenderBmodelFace (entity_t ent, bedge_t *pedges, msurface_t *psurf)
{
int i;
unsigned int mask;
@ -610,7 +614,7 @@ R_RenderBmodelFace (entity_t *ent, bedge_t *pedges, msurface_t *psurf)
void
R_RenderPoly (entity_t *ent, msurface_t *fa, int clipflags)
R_RenderPoly (entity_t ent, msurface_t *fa, int clipflags)
{
int i, lindex, lnumverts, s_axis, t_axis;
float dist, lastdist, lzi, scale, u, v, frac;
@ -623,7 +627,9 @@ R_RenderPoly (entity_t *ent, msurface_t *fa, int clipflags)
polyvert_t pverts[100]; // FIXME: do real number, safely
int vertpage, newverts, newpage, lastvert;
qboolean visible;
mod_brush_t *brush = &ent->renderer.model->brush;
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer,
r_refdef.scene->reg);
mod_brush_t *brush = &renderer->model->brush;
// FIXME: clean this up and make it faster
// FIXME: guard against running out of vertices
@ -778,7 +784,7 @@ R_RenderPoly (entity_t *ent, msurface_t *fa, int clipflags)
void
R_ZDrawSubmodelPolys (entity_t *ent, model_t *model)
R_ZDrawSubmodelPolys (entity_t ent, model_t *model)
{
int i, numsurfaces;
msurface_t *psurf;

View file

@ -45,7 +45,9 @@
#include "QF/skin.h"
#include "QF/sys.h"
#include "QF/scene/component.h"
#include "QF/scene/entity.h"
#include "QF/scene/scene.h"
#include "d_ifacea.h"
#include "r_internal.h"
@ -211,7 +213,7 @@ R_IQMPreparePoints (iqm_t *iqm, swiqm_t *sw, iqmframe_t *frame)
}
static void
R_IQMSetupLighting (entity_t *ent, alight_t *plighting)
R_IQMSetupLighting (entity_t ent, alight_t *plighting)
{
// guarantee that no vertex will ever be lit below LIGHT_MIN, so we don't
// have to clamp off the bottom
@ -234,7 +236,8 @@ R_IQMSetupLighting (entity_t *ent, alight_t *plighting)
// rotate the lighting vector into the model's frame of reference
mat4f_t mat;
Transform_GetWorldMatrix (ent->transform, mat);
transform_t transform = Entity_Transform (ent);
Transform_GetWorldMatrix (transform, mat);
//FIXME vectorize
r_lightvec[0] = DotProduct (plighting->lightvec, mat[0]);
r_lightvec[1] = DotProduct (plighting->lightvec, mat[1]);
@ -242,14 +245,15 @@ R_IQMSetupLighting (entity_t *ent, alight_t *plighting)
}
static void
R_IQMSetUpTransform (entity_t *ent, int trivial_accept)
R_IQMSetUpTransform (entity_t ent, int trivial_accept)
{
int i;
float rotationmatrix[3][4];
vec3_t forward, left, up;
mat4f_t mat;
Transform_GetWorldMatrix (ent->transform, mat);
transform_t transform = Entity_Transform (ent);
Transform_GetWorldMatrix (transform, mat);
VectorCopy (mat[0], forward);
VectorCopy (mat[1], left);
VectorCopy (mat[2], up);
@ -286,9 +290,15 @@ R_IQMSetUpTransform (entity_t *ent, int trivial_accept)
}
void
R_IQMDrawModel (entity_t *ent, alight_t *plighting)
R_IQMDrawModel (entity_t ent, alight_t *plighting)
{
model_t *model = ent->renderer.model;
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer,
r_refdef.scene->reg);
visibility_t *visibility = Ent_GetComponent (ent.id, scene_visibility,
r_refdef.scene->reg);
animation_t *animation = Ent_GetComponent (ent.id, scene_animation,
r_refdef.scene->reg);
model_t *model = renderer->model;
iqm_t *iqm = (iqm_t *) model->aliashdr;
swiqm_t *sw = (swiqm_t *) iqm->extra_data;
int size;
@ -298,8 +308,8 @@ R_IQMDrawModel (entity_t *ent, alight_t *plighting)
size = (CACHE_SIZE - 1)
+ sizeof (finalvert_t) * (iqm->num_verts + 1)
+ sizeof (auxvert_t) * iqm->num_verts;
blend = R_IQMGetLerpedFrames (ent, iqm);
frame = R_IQMBlendPalette (iqm, ent->animation.pose1, ent->animation.pose2,
blend = R_IQMGetLerpedFrames (animation, iqm);
frame = R_IQMBlendPalette (iqm, animation->pose1, animation->pose2,
blend, size, sw->blend_palette,
sw->palette_size);
@ -308,21 +318,22 @@ R_IQMDrawModel (entity_t *ent, alight_t *plighting)
(((intptr_t) &pfinalverts[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
pauxverts = (auxvert_t *) &pfinalverts[iqm->num_verts + 1];
R_IQMSetUpTransform (ent, ent->visibility.trivial_accept);
R_IQMSetUpTransform (ent, visibility->trivial_accept);
R_IQMSetupLighting (ent, plighting);
r_affinetridesc.drawtype = (ent->visibility.trivial_accept == 3) &&
r_affinetridesc.drawtype = (visibility->trivial_accept == 3) &&
r_recursiveaffinetriangles;
//if (!acolormap)
acolormap = r_colormap;
if (ent != vr_data.view_model)
//FIXME depth hack
if (ent.id != vr_data.view_model.id)
ziscale = (float) 0x8000 *(float) 0x10000;
else
ziscale = (float) 0x8000 *(float) 0x10000 *3.0;
if (ent->visibility.trivial_accept)
if (visibility->trivial_accept)
R_IQMPrepareUnclippedPoints (iqm, sw, frame);
else
R_IQMPreparePoints (iqm, sw, frame);

View file

@ -42,6 +42,7 @@
#include "QF/cmd.h"
#include "QF/scene/component.h"
#include "QF/scene/entity.h"
#include "QF/scene/scene.h"
@ -151,6 +152,7 @@ R_NewScene (scene_t *scene)
model_t *worldmodel = scene->worldmodel;
mod_brush_t *brush = &worldmodel->brush;
r_refdef.scene = scene;
r_refdef.worldmodel = worldmodel;
// clear out efrags in case the level hasn't been reloaded
@ -217,13 +219,13 @@ R_SetColormap (const byte *cmap)
}
static inline void
draw_sprite_entity (entity_t *ent)
draw_sprite_entity (entity_t ent)
{
R_DrawSprite (ent);
}
static inline void
setup_lighting (entity_t *ent, alight_t *lighting)
setup_lighting (entity_t ent, alight_t *lighting)
{
float minlight = 0;
int j;
@ -232,7 +234,9 @@ setup_lighting (entity_t *ent, alight_t *lighting)
float add;
float lightvec[3] = { -1, 0, 0 };
minlight = max (ent->renderer.model->min_light, ent->renderer.min_light);
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer,
r_refdef.scene->reg);
minlight = max (renderer->model->min_light, renderer->min_light);
// 128 instead of 255 due to clamping below
j = max (R_LightPoint (&r_refdef.worldmodel->brush, r_entorigin),
@ -261,11 +265,13 @@ setup_lighting (entity_t *ent, alight_t *lighting)
}
static inline void
draw_alias_entity (entity_t *ent)
draw_alias_entity (entity_t ent)
{
// see if the bounding box lets us trivially reject, also
// sets trivial accept status
ent->visibility.trivial_accept = 0; //FIXME
visibility_t *visibility = Ent_GetComponent (ent.id, scene_visibility,
r_refdef.scene->reg);
visibility->trivial_accept = 0; //FIXME
if (R_AliasCheckBBox (ent)) {
alight_t lighting;
setup_lighting (ent, &lighting);
@ -274,11 +280,13 @@ draw_alias_entity (entity_t *ent)
}
static inline void
draw_iqm_entity (entity_t *ent)
draw_iqm_entity (entity_t ent)
{
// see if the bounding box lets us trivially reject, also
// sets trivial accept status
ent->visibility.trivial_accept = 0; //FIXME
visibility_t *visibility = Ent_GetComponent (ent.id, scene_visibility,
r_refdef.scene->reg);
visibility->trivial_accept = 0; //FIXME
alight_t lighting;
setup_lighting (ent, &lighting);
@ -296,8 +304,9 @@ R_DrawEntitiesOnList (entqueue_t *queue)
do { \
for (size_t i = 0; i < queue->ent_queues[mod_##type_name].size; \
i++) { \
entity_t *ent = queue->ent_queues[mod_##type_name].a[i]; \
r_entorigin = Transform_GetWorldPosition (ent->transform); \
entity_t ent = queue->ent_queues[mod_##type_name].a[i]; \
transform_t transform = Entity_Transform (ent); \
r_entorigin = Transform_GetWorldPosition (transform); \
draw_##type_name##_entity (ent); \
} \
} while (0)
@ -319,7 +328,7 @@ R_DrawViewModel (void)
float add;
float minlight;
dlight_t *dl;
entity_t *viewent;
entity_t viewent;
alight_t lighting;
if (vr_data.inhibit_viewmodel
@ -328,15 +337,18 @@ R_DrawViewModel (void)
return;
viewent = vr_data.view_model;
if (!viewent->renderer.model)
renderer_t *renderer = Ent_GetComponent (viewent.id, scene_renderer,
r_refdef.scene->reg);
transform_t transform = Entity_Transform (viewent);
if (!renderer->model)
return;
VectorCopy (Transform_GetWorldPosition (viewent->transform), r_entorigin);
VectorCopy (Transform_GetWorldPosition (transform), r_entorigin);
VectorNegate (vup, lighting.lightvec);
minlight = max (viewent->renderer.min_light,
viewent->renderer.model->min_light);
minlight = max (renderer->min_light, renderer->model->min_light);
j = max (R_LightPoint (&r_refdef.worldmodel->brush,
r_entorigin), minlight * 128);
@ -370,7 +382,7 @@ R_DrawViewModel (void)
}
static int
R_BmodelCheckBBox (entity_t *ent, model_t *clmodel, float *minmaxs)
R_BmodelCheckBBox (entity_t ent, model_t *clmodel, float *minmaxs)
{
int i, *pindex, clipflags;
vec3_t acceptpt, rejectpt;
@ -379,7 +391,8 @@ R_BmodelCheckBBox (entity_t *ent, model_t *clmodel, float *minmaxs)
clipflags = 0;
Transform_GetWorldMatrix (ent->transform, mat);
transform_t transform = Entity_Transform (ent);
Transform_GetWorldMatrix (transform, mat);
if (mat[0][0] != 1 || mat[1][1] != 1 || mat[2][2] != 1) {
for (i = 0; i < 4; i++) {
d = DotProduct (mat[3], view_clipplanes[i].normal);
@ -439,10 +452,15 @@ R_DrawBrushEntitiesOnList (entqueue_t *queue)
insubmodel = true;
for (size_t i = 0; i < queue->ent_queues[mod_brush].size; i++) {
entity_t *ent = queue->ent_queues[mod_brush].a[i];
entity_t ent = queue->ent_queues[mod_brush].a[i];
VectorCopy (Transform_GetWorldPosition (ent->transform), origin);
clmodel = ent->renderer.model;
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer,
r_refdef.scene->reg);
transform_t transform = Entity_Transform (ent);
visibility_t *visibility = Ent_GetComponent (ent.id, scene_visibility,
r_refdef.scene->reg);
VectorCopy (Transform_GetWorldPosition (transform), origin);
clmodel = renderer->model;
// see if the bounding box lets us trivially reject, also
// sets trivial accept status
@ -461,7 +479,7 @@ R_DrawBrushEntitiesOnList (entqueue_t *queue)
r_pcurrentvertbase = brush->vertexes;
// FIXME: stop transforming twice
R_RotateBmodel (ent->transform);
R_RotateBmodel (transform);
// calculate dynamic lighting for bmodel if it's not an
// instanced model
@ -486,7 +504,7 @@ R_DrawBrushEntitiesOnList (entqueue_t *queue)
if (r_drawpolys | r_drawculledpolys) {
R_ZDrawSubmodelPolys (ent, clmodel);
} else {
int topnode_id = ent->visibility.topnode_id;
int topnode_id = visibility->topnode_id;
mod_brush_t *brush = &r_refdef.worldmodel->brush;
if (topnode_id >= 0) {
@ -583,7 +601,7 @@ R_RenderView_ (void)
R_EdgeDrawing (r_ent_queue);
if (vr_data.view_model) {
if (Entity_Valid (vr_data.view_model)) {
R_DrawViewModel ();
}

View file

@ -40,7 +40,9 @@
#include "QF/render.h"
#include "QF/sys.h"
#include "QF/scene/component.h"
#include "QF/scene/entity.h"
#include "QF/scene/scene.h"
#include "r_internal.h"
@ -241,13 +243,18 @@ R_SetupAndDrawSprite (const vec3_t relvieworg)
}
void
R_DrawSprite (entity_t *ent)
R_DrawSprite (entity_t ent)
{
msprite_t *sprite = ent->renderer.model->cache.data;
transform_t transform = Entity_Transform (ent);
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer,
r_refdef.scene->reg);
animation_t *animation = Ent_GetComponent (ent.id, scene_animation,
r_refdef.scene->reg);
msprite_t *sprite = renderer->model->cache.data;
vec4f_t cameravec = r_refdef.frame.position - r_entorigin;
r_spritedesc.pspriteframe = R_GetSpriteFrame (sprite, &ent->animation);
r_spritedesc.pspriteframe = R_GetSpriteFrame (sprite, animation);
sprite_width = r_spritedesc.pspriteframe->width;
sprite_height = r_spritedesc.pspriteframe->height;
@ -255,7 +262,8 @@ R_DrawSprite (entity_t *ent)
vec4f_t up = {};
vec4f_t right = {};
vec4f_t fwd = {};
if (!R_BillboardFrame (ent, sprite->type, cameravec, &up, &right, &fwd)) {
if (!R_BillboardFrame (transform, sprite->type, cameravec,
&up, &right, &fwd)) {
// the orientation is undefined so can't draw the sprite
return;
}

View file

@ -73,7 +73,7 @@ static unsigned int blocklights[34 * 34]; //FIXME make dynamic
static void
R_AddDynamicLights (transform_t *transform)
R_AddDynamicLights (transform_t transform)
{
msurface_t *surf;
unsigned int lnum;
@ -91,7 +91,7 @@ R_AddDynamicLights (transform_t *transform)
tmax = (surf->extents[1] >> 4) + 1;
tex = surf->texinfo;
if (transform) {
if (Transform_Valid (transform)) {
//FIXME give world entity a transform
entorigin = Transform_GetWorldPosition (transform);
}
@ -144,7 +144,7 @@ R_AddDynamicLights (transform_t *transform)
Combine and scale multiple lightmaps into the 8.8 format in blocklights
*/
static void
R_BuildLightMap (transform_t *transform)
R_BuildLightMap (transform_t transform)
{
int smax, tmax;
int t;
@ -194,7 +194,7 @@ R_BuildLightMap (transform_t *transform)
}
void
R_DrawSurface (transform_t *transform)
R_DrawSurface (transform_t transform)
{
byte *basetptr;
int smax, tmax, twidth;

View file

@ -31,6 +31,8 @@
#include "QF/plugin/general.h"
#include "QF/plugin/vid_render.h"
#include "QF/scene/component.h"
#include "QF/ui/view.h"
#include "mod_internal.h"
@ -54,7 +56,7 @@ vid_render_data_t vid_render_data = {
.inhibit_viewmodel = false,
.paused = false,
.lineadj = 0,
.view_model = 0,
.view_model = nullentity,
.frametime = 0.0,
.realtime = 0.0,
.lightstyle = 0,

View file

@ -38,7 +38,9 @@
#include "QF/cvar.h"
#include "QF/va.h"
#include "QF/scene/component.h"
#include "QF/scene/entity.h"
#include "QF/scene/scene.h"
#include "QF/Vulkan/qf_alias.h"
#include "QF/Vulkan/qf_matrices.h"
@ -76,7 +78,7 @@ static void
emit_commands (VkCommandBuffer cmd, int pose1, int pose2,
qfv_alias_skin_t *skin,
uint32_t numPC, qfv_push_constants_t *constants,
aliashdr_t *hdr, qfv_renderframe_t *rFrame, entity_t *ent)
aliashdr_t *hdr, qfv_renderframe_t *rFrame, entity_t ent)
{
vulkan_ctx_t *ctx = rFrame->vulkan_ctx;
qfv_device_t *device = ctx->device;
@ -116,15 +118,19 @@ emit_commands (VkCommandBuffer cmd, int pose1, int pose2,
}
void
Vulkan_DrawAlias (entity_t *ent, qfv_renderframe_t *rFrame)
Vulkan_DrawAlias (entity_t ent, qfv_renderframe_t *rFrame)
{
transform_t transform = Entity_Transform (ent);
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer,
r_refdef.scene->reg);
animation_t *animation = Ent_GetComponent (ent.id, scene_animation,
r_refdef.scene->reg);
vulkan_ctx_t *ctx = rFrame->vulkan_ctx;
aliasctx_t *actx = ctx->alias_context;
aliasframe_t *aframe = &actx->frames.a[ctx->curFrame];
model_t *model = ent->renderer.model;
model_t *model = renderer->model;
aliashdr_t *hdr;
qfv_alias_skin_t *skin;
animation_t *animation = &ent->animation;
alias_push_constants_t constants = {};
if (!(hdr = model->aliashdr)) {
@ -136,7 +142,7 @@ Vulkan_DrawAlias (entity_t *ent, qfv_renderframe_t *rFrame)
qfv_push_constants_t push_constants[] = {
{ VK_SHADER_STAGE_VERTEX_BIT,
field_offset (alias_push_constants_t, mat),
sizeof (mat4f_t), Transform_GetWorldMatrixPtr (ent->transform) },
sizeof (mat4f_t), Transform_GetWorldMatrixPtr (transform) },
{ VK_SHADER_STAGE_VERTEX_BIT,
field_offset (alias_push_constants_t, blend),
sizeof (float), &constants.blend },
@ -158,19 +164,19 @@ Vulkan_DrawAlias (entity_t *ent, qfv_renderframe_t *rFrame)
//skin = ent->skin->tex;
} else {
maliasskindesc_t *skindesc;
skindesc = R_AliasGetSkindesc (animation, ent->renderer.skinnum, hdr);
skindesc = R_AliasGetSkindesc (animation, renderer->skinnum, hdr);
skin = (qfv_alias_skin_t *) ((byte *) hdr + skindesc->skin);
}
QuatCopy (ent->renderer.colormod, constants.base_color);
QuatCopy (renderer->colormod, constants.base_color);
QuatCopy (skin->colora, constants.colorA);
QuatCopy (skin->colorb, constants.colorB);
QuatZero (constants.fog);
emit_commands (aframe->cmdSet.a[QFV_aliasDepth],
ent->animation.pose1, ent->animation.pose2,
animation->pose1, animation->pose2,
0, 2, push_constants, hdr, rFrame, ent);
emit_commands (aframe->cmdSet.a[QFV_aliasGBuffer],
ent->animation.pose1, ent->animation.pose2,
animation->pose1, animation->pose2,
skin, 6, push_constants, hdr, rFrame, ent);
}

View file

@ -52,7 +52,9 @@
#include "QF/va.h"
#include "QF/math/bitop.h"
#include "QF/scene/component.h"
#include "QF/scene/entity.h"
#include "QF/scene/scene.h"
#include "QF/Vulkan/qf_bsp.h"
#include "QF/Vulkan/qf_lightmap.h"
@ -583,16 +585,20 @@ Vulkan_BuildDisplayLists (model_t **models, int num_models, vulkan_ctx_t *ctx)
}
static int
R_DrawBrushModel (entity_t *e, bsp_pass_t *pass, vulkan_ctx_t *ctx)
R_DrawBrushModel (entity_t ent, bsp_pass_t *pass, vulkan_ctx_t *ctx)
{
transform_t transform = Entity_Transform (ent);
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer,
r_refdef.scene->reg);
animation_t *animation = Ent_GetComponent (ent.id, scene_animation,
r_refdef.scene->reg);
float radius;
model_t *model;
model_t *model = renderer->model;
vec3_t mins, maxs;
bspctx_t *bctx = ctx->bsp_context;
model = e->renderer.model;
mat4f_t mat;
Transform_GetWorldMatrix (e->transform, mat);
Transform_GetWorldMatrix (transform, mat);
if (mat[0][0] != 1 || mat[1][1] != 1 || mat[2][2] != 1) {
radius = model->radius;
if (R_CullSphere (pass->frustum, (vec_t*)&mat[3], radius)) { //FIXME
@ -604,13 +610,13 @@ R_DrawBrushModel (entity_t *e, bsp_pass_t *pass, vulkan_ctx_t *ctx)
if (R_CullBox (pass->frustum, mins, maxs))
return 1;
}
if (Vulkan_Scene_AddEntity (ctx, e) < 0) {
if (Vulkan_Scene_AddEntity (ctx, ent) < 0) {
return 0;
}
pass->ent_frame = e->animation.frame & 1;
pass->ent_frame = animation->frame & 1;
pass->inst_id = model->render_id;
pass->inst_id |= e->renderer.colormod[3] < 1 ? INST_ALPHA : 0;
pass->inst_id |= renderer->colormod[3] < 1 ? INST_ALPHA : 0;
if (!pass->instances[model->render_id].entities.size) {
bsp_model_t *m = &bctx->models[model->render_id];
bsp_face_t *face = &bctx->faces[m->first_face];
@ -620,7 +626,7 @@ R_DrawBrushModel (entity_t *e, bsp_pass_t *pass, vulkan_ctx_t *ctx)
}
}
DARRAY_APPEND (&pass->instances[model->render_id].entities,
e->renderer.render_id);
renderer->render_id);
return 1;
}
@ -1028,9 +1034,13 @@ draw_queue (bsp_pass_t *pass, int queue, VkPipelineLayout layout,
static int
ent_model_cmp (const void *_a, const void *_b)
{
const entity_t * const *a = _a;
const entity_t * const *b = _b;
return (*a)->renderer.model->render_id - (*b)->renderer.model->render_id;
const entity_t *a = _a;
const entity_t *b = _b;
renderer_t *ra = Ent_GetComponent (a->id, scene_renderer,
r_refdef.scene->reg);
renderer_t *rb = Ent_GetComponent (b->id, scene_renderer,
r_refdef.scene->reg);
return ra->model->render_id - rb->model->render_id;
}
void
@ -1057,22 +1067,15 @@ Vulkan_DrawWorld (qfv_renderframe_t *rFrame)
clear_queues (bctx, &bctx->main_pass); // do this first for water and skys
bframe->index_count = 0;
entity_t worldent = {
.renderer = {
.model = r_refdef.worldmodel,
.colormod = { 1, 1, 1, 1 },
},
};
entity_t worldent = nullentity;
Vulkan_Scene_AddEntity (ctx, &worldent);
int world_id = Vulkan_Scene_AddEntity (ctx, worldent);
int world_id = worldent.renderer.model->render_id;
bctx->main_pass.ent_frame = 0; // world is always frame 0
bctx->main_pass.inst_id = world_id;
bctx->main_pass.brush = &worldent.renderer.model->brush;
bctx->main_pass.brush = &r_refdef.worldmodel->brush;
if (bctx->main_pass.instances) {
DARRAY_APPEND (&bctx->main_pass.instances[world_id].entities,
worldent.renderer.render_id);
DARRAY_APPEND (&bctx->main_pass.instances[world_id].entities, world_id);
}
R_VisitWorldNodes (&bctx->main_pass, ctx);
if (!bctx->vertex_buffer) {
@ -1081,9 +1084,9 @@ Vulkan_DrawWorld (qfv_renderframe_t *rFrame)
if (r_drawentities) {
heapsort (r_ent_queue->ent_queues[mod_brush].a,
r_ent_queue->ent_queues[mod_brush].size,
sizeof (entity_t *), ent_model_cmp);
sizeof (entity_t), ent_model_cmp);
for (size_t i = 0; i < r_ent_queue->ent_queues[mod_brush].size; i++) {
entity_t *ent = r_ent_queue->ent_queues[mod_brush].a[i];
entity_t ent = r_ent_queue->ent_queues[mod_brush].a[i];
if (!R_DrawBrushModel (ent, &bctx->main_pass, ctx)) {
Sys_Printf ("Too many entities!\n");
break;

View file

@ -37,7 +37,9 @@
#include "QF/iqm.h"
#include "QF/va.h"
#include "QF/scene/component.h"
#include "QF/scene/entity.h"
#include "QF/scene/scene.h"
#include "QF/Vulkan/qf_iqm.h"
#include "QF/Vulkan/qf_matrices.h"
@ -77,7 +79,7 @@ static void
emit_commands (VkCommandBuffer cmd, int pose1, int pose2,
qfv_iqm_skin_t *skins,
uint32_t numPC, qfv_push_constants_t *constants,
iqm_t *iqm, qfv_renderframe_t *rFrame, entity_t *ent)
iqm_t *iqm, qfv_renderframe_t *rFrame, entity_t ent)
{
vulkan_ctx_t *ctx = rFrame->vulkan_ctx;
qfv_device_t *device = ctx->device;
@ -126,22 +128,27 @@ emit_commands (VkCommandBuffer cmd, int pose1, int pose2,
#define a(x) ((x) & ~0x3f)
void
Vulkan_DrawIQM (entity_t *ent, qfv_renderframe_t *rFrame)
Vulkan_DrawIQM (entity_t ent, qfv_renderframe_t *rFrame)
{
transform_t transform = Entity_Transform (ent);
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer,
r_refdef.scene->reg);
animation_t *animation = Ent_GetComponent (ent.id, scene_animation,
r_refdef.scene->reg);
vulkan_ctx_t *ctx = rFrame->vulkan_ctx;
qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs;
iqmctx_t *ictx = ctx->iqm_context;
iqm_frame_t *aframe = &ictx->frames.a[ctx->curFrame];
model_t *model = ent->renderer.model;
model_t *model = renderer->model;
iqm_t *iqm = (iqm_t *) model->aliashdr;
qfv_iqm_t *mesh = iqm->extra_data;
qfv_iqm_skin_t *skins = mesh->skins;
iqm_push_constants_t constants = {};
iqmframe_t *frame;
constants.blend = R_IQMGetLerpedFrames (ent, iqm);
frame = R_IQMBlendFrames (iqm, ent->animation.pose1, ent->animation.pose2,
constants.blend = R_IQMGetLerpedFrames (animation, iqm);
frame = R_IQMBlendFrames (iqm, animation->pose1, animation->pose2,
constants.blend, 0);
vec4f_t *bone_data;
@ -170,7 +177,7 @@ Vulkan_DrawIQM (entity_t *ent, qfv_renderframe_t *rFrame)
qfv_push_constants_t push_constants[] = {
{ VK_SHADER_STAGE_VERTEX_BIT,
field_offset (iqm_push_constants_t, mat),
sizeof (mat4f_t), Transform_GetWorldMatrixPtr (ent->transform) },
sizeof (mat4f_t), Transform_GetWorldMatrixPtr (transform) },
{ VK_SHADER_STAGE_VERTEX_BIT,
field_offset (iqm_push_constants_t, blend),
sizeof (float), &constants.blend },
@ -188,16 +195,16 @@ Vulkan_DrawIQM (entity_t *ent, qfv_renderframe_t *rFrame)
sizeof (constants.fog), &constants.fog },
};
QuatCopy (ent->renderer.colormod, constants.base_color);
QuatCopy (renderer->colormod, constants.base_color);
QuatCopy (skins[0].colora, constants.colorA);
QuatCopy (skins[0].colorb, constants.colorB);
QuatZero (constants.fog);
emit_commands (aframe->cmdSet.a[QFV_iqmDepth],
ent->animation.pose1, ent->animation.pose2,
animation->pose1, animation->pose2,
0, 2, push_constants, iqm, rFrame, ent);
emit_commands (aframe->cmdSet.a[QFV_iqmGBuffer],
ent->animation.pose1, ent->animation.pose2,
animation->pose1, animation->pose2,
skins, 6, push_constants, iqm, rFrame, ent);
}

View file

@ -45,6 +45,7 @@
#include "QF/screen.h"
#include "QF/sys.h"
#include "QF/scene/component.h"
#include "QF/scene/entity.h"
#include "QF/scene/scene.h"
@ -78,19 +79,19 @@ Vulkan_RenderEntities (entqueue_t *queue, qfv_renderframe_t *rFrame)
int begun = 0; \
for (size_t i = 0; i < queue->ent_queues[mod_##type_name].size; \
i++) { \
entity_t *ent = queue->ent_queues[mod_##type_name].a[i]; \
entity_t ent = queue->ent_queues[mod_##type_name].a[i]; \
if (!begun) { \
Vulkan_##Type##Begin (rFrame); \
begun = 1; \
} \
/* hack the depth range to prevent view model */\
/* FIXME hack the depth range to prevent view model */\
/* from poking into walls */\
if (ent == vr_data.view_model) { \
if (ent.id == vr_data.view_model.id) { \
Vulkan_AliasDepthRange (rFrame, 0, 0.3); \
} \
Vulkan_Draw##Type (ent, rFrame); \
/* unhack in case the view_model is not the last */\
if (ent == vr_data.view_model) { \
if (ent.id == vr_data.view_model.id) { \
Vulkan_AliasDepthRange (rFrame, 0, 1); \
} \
} \
@ -106,14 +107,16 @@ Vulkan_RenderEntities (entqueue_t *queue, qfv_renderframe_t *rFrame)
static void
Vulkan_DrawViewModel (vulkan_ctx_t *ctx)
{
entity_t *ent = vr_data.view_model;
entity_t ent = vr_data.view_model;
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer,
r_refdef.scene->reg);
if (vr_data.inhibit_viewmodel
|| !r_drawviewmodel
|| !r_drawentities
|| !ent->renderer.model)
|| !renderer->model)
return;
EntQueue_AddEntity (r_ent_queue, ent, ent->renderer.model->type);
EntQueue_AddEntity (r_ent_queue, ent, renderer->model->type);
}
void
@ -127,7 +130,7 @@ Vulkan_RenderView (qfv_renderframe_t *rFrame)
Vulkan_DrawWorld (rFrame);
Vulkan_DrawSky (rFrame);
if (vr_data.view_model) {
if (Entity_Valid (vr_data.view_model)) {
Vulkan_DrawViewModel (ctx);
}
Vulkan_DrawWaterSurfaces (rFrame);
@ -145,6 +148,7 @@ Vulkan_NewScene (scene_t *scene, vulkan_ctx_t *ctx)
d_lightstylevalue[i] = 264; // normal light value
}
r_refdef.scene = scene;
r_refdef.worldmodel = scene->worldmodel;
// Force a vis update

View file

@ -37,7 +37,9 @@
#include "QF/set.h"
#include "QF/va.h"
#include "QF/scene/component.h"
#include "QF/scene/entity.h"
#include "QF/scene/scene.h"
#include "QF/Vulkan/qf_scene.h"
#include "QF/Vulkan/debug.h"
@ -46,6 +48,7 @@
#include "QF/Vulkan/instance.h"
#include "QF/Vulkan/resource.h"
#include "r_internal.h"
#include "vid_vulkan.h"
static const int qfv_max_entities = 4096; //FIXME should make dynamic
@ -66,39 +69,50 @@ Vulkan_Scene_Descriptors (vulkan_ctx_t *ctx)
}
int
Vulkan_Scene_AddEntity (vulkan_ctx_t *ctx, entity_t *entity)
Vulkan_Scene_AddEntity (vulkan_ctx_t *ctx, entity_t entity)
{
scenectx_t *sctx = ctx->scene_context;
scnframe_t *sframe = &sctx->frames.a[ctx->curFrame];
entdata_t *entdata = 0;
//lock
int id = -entity->id;
int id = Ent_Index (entity.id + 1);//nullent -> 0
if (!set_is_member (sframe->pooled_entities, id)) {
if (sframe->entity_pool.size < sframe->entity_pool.maxSize) {
set_add (sframe->pooled_entities, id);
entity->renderer.render_id = sframe->entity_pool.size++;
entdata = sframe->entity_pool.a + entity->renderer.render_id;
id = sframe->entity_pool.size++;
entdata = sframe->entity_pool.a + id;
} else {
entity->renderer.render_id = -1;
id = -1;
}
}
if (Entity_Valid (entity)) {
renderer_t *renderer = Ent_GetComponent (entity.id, scene_renderer,
r_refdef.scene->reg);
renderer->render_id = -1;
}
//unlock
if (entdata) {
mat4f_t f;
if (entity->transform) { //FIXME give world entity an entity :P
mat4ftranspose (f, Transform_GetWorldMatrixPtr (entity->transform));
vec4f_t color;
if (Entity_Valid (entity)) { //FIXME give world entity an entity :P
transform_t transform = Entity_Transform (entity);
renderer_t *renderer = Ent_GetComponent (entity.id, scene_renderer,
r_refdef.scene->reg);
mat4ftranspose (f, Transform_GetWorldMatrixPtr (transform));
entdata->xform[0] = f[0];
entdata->xform[1] = f[1];
entdata->xform[2] = f[2];
color = (vec4f_t) { QuatExpand (renderer->colormod) };
} else {
entdata->xform[0] = (vec4f_t) { 1, 0, 0, 0 };
entdata->xform[1] = (vec4f_t) { 0, 1, 0, 0 };
entdata->xform[2] = (vec4f_t) { 0, 0, 1, 0 };
color = (vec4f_t) { 1, 1, 1, 1 };
}
entdata->color = (vec4f_t) { QuatExpand (entity->renderer.colormod) };
entdata->color = color;
}
return entity->renderer.render_id;
return id;
}
void

View file

@ -51,7 +51,9 @@
#include "QF/sys.h"
#include "QF/va.h"
#include "QF/scene/component.h"
#include "QF/scene/entity.h"
#include "QF/scene/scene.h"
#include "QF/Vulkan/qf_matrices.h"
#include "QF/Vulkan/qf_renderpass.h"
@ -82,7 +84,7 @@ static QFV_Subpass subpass_map[] = {
static void
emit_commands (VkCommandBuffer cmd, qfv_sprite_t *sprite,
int numPC, qfv_push_constants_t *constants,
qfv_renderframe_t *rFrame, entity_t *ent)
qfv_renderframe_t *rFrame, entity_t ent)
{
vulkan_ctx_t *ctx = rFrame->vulkan_ctx;
qfv_device_t *device = ctx->device;
@ -103,14 +105,18 @@ emit_commands (VkCommandBuffer cmd, qfv_sprite_t *sprite,
}
void
Vulkan_DrawSprite (entity_t *ent, qfv_renderframe_t *rFrame)
Vulkan_DrawSprite (entity_t ent, qfv_renderframe_t *rFrame)
{
transform_t transform = Entity_Transform (ent);
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer,
r_refdef.scene->reg);
animation_t *animation = Ent_GetComponent (ent.id, scene_animation,
r_refdef.scene->reg);
vulkan_ctx_t *ctx = rFrame->vulkan_ctx;
spritectx_t *sctx = ctx->sprite_context;
spriteframe_t *sframe = &sctx->frames.a[ctx->curFrame];
model_t *model = ent->renderer.model;
model_t *model = renderer->model;
msprite_t *sprite = model->cache.data;
animation_t *animation = &ent->animation;
mat4f_t mat = {};
uint32_t frame;
@ -122,9 +128,9 @@ Vulkan_DrawSprite (entity_t *ent, qfv_renderframe_t *rFrame)
frame = (ptrdiff_t) R_GetSpriteFrame (sprite, animation);
mat[3] = Transform_GetWorldPosition (ent->transform);
mat[3] = Transform_GetWorldPosition (transform);
vec4f_t cameravec = r_refdef.frame.position - mat[3];
R_BillboardFrame (ent, sprite->type, cameravec,
R_BillboardFrame (transform, sprite->type, cameravec,
&mat[2], &mat[1], &mat[0]);
mat[0] = -mat[0];

View file

@ -42,7 +42,9 @@
#include "QF/heapsort.h"
#include "QF/plist.h"
#include "QF/va.h"
#include "QF/scene/component.h"
#include "QF/scene/entity.h"
#include "QF/scene/scene.h"
#include "QF/Vulkan/capture.h"
#include "QF/Vulkan/command.h"
#include "QF/Vulkan/debug.h"
@ -582,16 +584,17 @@ Vulkan_DestroyFrames (vulkan_ctx_t *ctx)
}
void
Vulkan_BeginEntityLabel (vulkan_ctx_t *ctx, VkCommandBuffer cmd,
entity_t *ent)
Vulkan_BeginEntityLabel (vulkan_ctx_t *ctx, VkCommandBuffer cmd, entity_t ent)
{
qfv_device_t *device = ctx->device;
int entaddr = (intptr_t) ent & 0xfffff;
vec4f_t pos = Transform_GetWorldPosition (ent->transform);
uint32_t entgen = Ent_Generation (ent.id);
uint32_t entind = Ent_Index (ent.id);
transform_t transform = Entity_Transform (ent);
vec4f_t pos = Transform_GetWorldPosition (transform);
vec4f_t dir = normalf (pos - (vec4f_t) { 0, 0, 0, 1 });
vec4f_t color = 0.5 * dir + (vec4f_t) {0.5, 0.5, 0.5, 1 };
QFV_CmdBeginLabel (device, cmd,
va (ctx->va_ctx, "ent %05x [%g, %g, %g]", entaddr,
VectorExpand (pos)), color);
va (ctx->va_ctx, "ent %03x.%05x [%g, %g, %g]",
entgen, entind, VectorExpand (pos)), color);
}

View file

@ -35,6 +35,9 @@
#include "QF/quakefs.h"
#include "QF/render.h"
#include "QF/scene/component.h"
#include "QF/scene/entity.h"
#include "client/chase.h"
#include "client/entities.h"
#include "client/input.h"
@ -218,7 +221,7 @@ extern int noskins;
extern client_state_t cl;
extern struct entity_s *cl_entities[MAX_EDICTS];
extern struct entity_s cl_entities[MAX_EDICTS];
extern double cl_msgtime[MAX_EDICTS];
extern struct set_s cl_forcelink;
@ -278,7 +281,7 @@ void CL_NewTranslation (int slot, struct skin_s *skin);
void CL_SignonReply (void);
void CL_RelinkEntities (void);
void CL_ClearEnts (void);
struct entity_s *CL_GetEntity (int num);
struct entity_s CL_GetEntity (int num);
extern double realtime;

View file

@ -59,7 +59,7 @@
#include "nq/include/host.h"
#include "nq/include/server.h"
entity_t *cl_entities[MAX_EDICTS];
entity_t cl_entities[MAX_EDICTS];
double cl_msgtime[MAX_EDICTS];
static byte forcelink_bytes[SET_SIZE(MAX_EDICTS)];
#define alloc_forcelink(s) (set_bits_t *)forcelink_bytes
@ -72,10 +72,14 @@ CL_ClearEnts (void)
size_t i;
for (i = 0; i < MAX_EDICTS; i++) {
if (cl_entities[i]) {
mod_funcs->Skin_Free (cl_entities[i]->renderer.skin);
if (Entity_Valid (cl_entities[i])) {
entity_t ent = cl_entities[i];
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, ent.reg);
if (renderer && renderer->skin) {
mod_funcs->Skin_Free (renderer->skin);
}
Scene_DestroyEntity (cl_world.scene, cl_entities[i]);
cl_entities[i] = 0;
cl_entities[i] = nullentity;
}
}
@ -86,10 +90,10 @@ CL_ClearEnts (void)
set_empty (&cl_forcelink);
}
entity_t *
entity_t
CL_GetEntity (int num)
{
if (!cl_entities[num]) {
if (!Entity_Valid (cl_entities[num])) {
cl_entities[num] = Scene_CreateEntity (cl_world.scene);
CL_Init_Entity (cl_entities[num]);
}
@ -136,9 +140,9 @@ CL_LerpPoint (void)
static void
set_entity_model (int ent_ind, int modelindex)
{
entity_t *ent = cl_entities[ent_ind];
renderer_t *renderer = &ent->renderer;
animation_t *animation = &ent->animation;
entity_t ent = cl_entities[ent_ind];
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, cl_world.scene->reg);
animation_t *animation = Ent_GetComponent (ent.id, scene_animation, cl_world.scene->reg);
renderer->model = cl_world.models.a[modelindex];
// automatic animation (torches, etc) can be either all together
// or randomized
@ -161,10 +165,8 @@ set_entity_model (int ent_ind, int modelindex)
void
CL_RelinkEntities (void)
{
entity_t *ent;
entity_t ent;
entity_state_t *new, *old;
renderer_t *renderer;
animation_t *animation;
float bobjrotate, frac, f;
int i, j;
int entvalid;
@ -199,8 +201,11 @@ CL_RelinkEntities (void)
new = &nq_entstates.frame[0 + cl.frameIndex][i];
old = &nq_entstates.frame[1 - cl.frameIndex][i];
ent = CL_GetEntity (i);
renderer = &ent->renderer;
animation = &ent->animation;
transform_t transform = Entity_Transform (ent);
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, cl_world.scene->reg);
animation_t *animation = Ent_GetComponent (ent.id, scene_animation, cl_world.scene->reg);
visibility_t *visibility = Ent_GetComponent (ent.id, scene_visibility, cl_world.scene->reg);
vec4f_t *old_origin = Ent_GetComponent (ent.id, scene_old_origin, cl_world.scene->reg);
// if the object wasn't included in the last packet, remove it
entvalid = cl_msgtime[i] == cl.mtime[0];
@ -212,7 +217,7 @@ CL_RelinkEntities (void)
if (!entvalid) {
renderer->model = NULL;
animation->pose1 = animation->pose2 = -1;
if (ent->visibility.efrag) {
if (visibility->efrag) {
R_RemoveEfrags (ent); // just became empty
}
continue;
@ -261,16 +266,16 @@ CL_RelinkEntities (void)
CL_TransformEntity (ent, new->scale / 16.0, new->angles,
new->origin);
if (i != cl.viewentity || chase_active) {
if (ent->visibility.efrag) {
if (visibility->efrag) {
R_RemoveEfrags (ent);
}
R_AddEfrags (&cl_world.scene->worldmodel->brush, ent);
}
ent->old_origin = new->origin;
*old_origin = new->origin;
} else {
vec4f_t delta = new->origin - old->origin;
f = frac;
ent->old_origin = Transform_GetWorldPosition (ent->transform);
*old_origin = Transform_GetWorldPosition (transform);
// If the delta is large, assume a teleport and don't lerp
if (fabs (delta[0]) > 100 || fabs (delta[1]) > 100
|| fabs (delta[2]) > 100) {
@ -295,10 +300,9 @@ CL_RelinkEntities (void)
CL_TransformEntity (ent, new->scale / 16.0, angles, origin);
}
if (i != cl.viewentity || chase_active) {
if (ent->visibility.efrag) {
vec4f_t org
= Transform_GetWorldPosition (ent->transform);
if (!VectorCompare (org, ent->old_origin)) {//FIXME
vec4f_t org = Transform_GetWorldPosition (transform);
if (visibility->efrag) {
if (!VectorCompare (org, *old_origin)) {//FIXME
R_RemoveEfrags (ent);
R_AddEfrags (&cl_world.scene->worldmodel->brush, ent);
}
@ -316,7 +320,7 @@ CL_RelinkEntities (void)
CL_TransformEntity (ent, new->scale / 16.0, angles, new->origin);
}
CL_EntityEffects (i, ent, new, cl.time);
vec4f_t org = Transform_GetWorldPosition (ent->transform);
vec4f_t org = Transform_GetWorldPosition (transform);
int effects = new->effects;
if (cl.maxclients == 1 && effects) {
// Enable blue and red lights for quad and invulnerability,
@ -340,7 +344,10 @@ CL_RelinkEntities (void)
SET_REMOVE (&cl_forcelink, i);
}
cl.viewstate.player_entity = CL_GetEntity (cl.viewentity);
cl.viewstate.player_origin
= Transform_GetWorldPosition (cl.viewstate.player_entity->transform);
{
entity_t player_entity = CL_GetEntity (cl.viewentity);
transform_t transform = Entity_Transform (player_entity);
cl.viewstate.player_entity = player_entity;
cl.viewstate.player_origin = Transform_GetWorldPosition (transform);
}
}

View file

@ -236,8 +236,9 @@ CL_ClearMemory (void)
cls.signon = 0;
SZ_Clear (&cls.message);
if (cl.viewstate.weapon_entity) {
if (Entity_Valid (cl.viewstate.weapon_entity)) {
Scene_DestroyEntity (cl_world.scene, cl.viewstate.weapon_entity);
cl.viewstate.weapon_entity = nullentity;
}
if (cl.players) {
int i;
@ -479,16 +480,19 @@ CL_PrintEntities_f (void)
int i;
for (i = 0; i < cl.num_entities; i++) {
entity_t *ent = cl_entities[i];
entity_t ent = cl_entities[i];
transform_t transform = Entity_Transform (ent);
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, cl_world.scene->reg);
animation_t *animation = Ent_GetComponent (ent.id, scene_animation, cl_world.scene->reg);
Sys_Printf ("%3i:", i);
if (!ent || !ent->renderer.model) {
if (!Entity_Valid (ent) || !renderer->model) {
Sys_Printf ("EMPTY\n");
continue;
}
vec4f_t org = Transform_GetWorldPosition (ent->transform);
vec4f_t rot = Transform_GetWorldRotation (ent->transform);
vec4f_t org = Transform_GetWorldPosition (transform);
vec4f_t rot = Transform_GetWorldRotation (transform);
Sys_Printf ("%s:%2i "VEC4F_FMT" "VEC4F_FMT"\n",
ent->renderer.model->path, ent->animation.frame,
renderer->model->path, animation->frame,
VEC4_EXP (org), VEC4_EXP (rot));
}
}
@ -674,7 +678,7 @@ CL_Frame (void)
S_Update (cl.viewstate.camera_transform, asl);
R_DecayLights (host_frametime);
} else
S_Update (0, 0);
S_Update (nulltransform, 0);
CDAudio_Update ();

View file

@ -673,12 +673,14 @@ CL_ParseClientdata (void)
cl.stats[STAT_CELLS] |= MSG_ReadByte (net_message) << 8;
if (bits & SU_WEAPONFRAME2)
cl.stats[STAT_WEAPONFRAME] |= MSG_ReadByte (net_message) << 8;
renderer_t *renderer = Ent_GetComponent (cl.viewstate.weapon_entity.id, scene_renderer, cl_world.scene->reg);
if (bits & SU_WEAPONALPHA) {
byte alpha = MSG_ReadByte (net_message);
float a = ENTALPHA_DECODE (alpha);
cl.viewstate.weapon_entity->renderer.colormod[3] = a;
renderer->colormod[3] = a;
} else {
cl.viewstate.weapon_entity->renderer.colormod[3] = 1;
renderer->colormod[3] = 1;
}
}
@ -904,7 +906,8 @@ CL_ParseServerMessage (void)
Host_Error ("CL_ParseServerMessage: svc_updatecolors > "
"MAX_SCOREBOARD");
} else {
entity_t *ent = CL_GetEntity (i + 1);
entity_t ent = CL_GetEntity (i + 1);
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, cl_world.scene->reg);
byte col = MSG_ReadByte (net_message);
byte top = col >> 4;
byte bot = col & 0xf;
@ -913,9 +916,8 @@ CL_ParseServerMessage (void)
mod_funcs->Skin_SetTranslation (i + 1, top, bot);
cl.players[i].topcolor = top;
cl.players[i].bottomcolor = bot;
ent->renderer.skin
= mod_funcs->Skin_SetColormap (ent->renderer.skin,
i + 1);
renderer->skin
= mod_funcs->Skin_SetColormap (renderer->skin, i + 1);
}
break;

View file

@ -41,7 +41,7 @@ void CL_ParsePacketEntities (qboolean delta);
void CL_SetSolidEntities (void);
void CL_ParsePlayerinfo (void);
void CL_Ents_Init (void);
struct entity_s *CL_GetEntity (int num);
struct entity_s CL_GetEntity (int num);
extern int cl_deadbodyfilter;
extern int cl_gibfilter;

View file

@ -282,8 +282,8 @@ extern int hud_scoreboard_uid;
extern client_state_t cl;
extern entity_t *cl_entities[512];
extern byte cl_entity_valid[2][512];
extern entity_t cl_entities[512];
extern byte cl_entity_valid[2][512];
extern qboolean nomaster;
extern char *server_version; // version of server we connected to

View file

@ -41,6 +41,8 @@
#include "QF/skin.h"
#include "QF/sys.h"
#include "QF/scene/component.h"
#include "QF/scene/entity.h"
#include "QF/scene/scene.h"
#include "compat.h"
@ -482,13 +484,15 @@ CL_ParsePlayerinfo (void)
// QSG2
int bits;
byte val;
entity_t *ent;
entity_t ent;
ent = CL_GetEntity (num + 1);
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer,
cl_world.scene->reg);
bits = MSG_ReadByte (net_message);
if (bits & PF_ALPHA) {
val = MSG_ReadByte (net_message);
ent->renderer.colormod[3] = val / 255.0;
renderer->colormod[3] = val / 255.0;
}
if (bits & PF_SCALE) {
val = MSG_ReadByte (net_message);
@ -511,7 +515,7 @@ CL_ParsePlayerinfo (void)
g = (float) ((val >> 2) & 7) * (1.0 / 7.0);
b = (float) (val & 3) * (1.0 / 3.0);
}
VectorSet (r, g, b, ent->renderer.colormod);
VectorSet (r, g, b, renderer->colormod);
}
if (bits & PF_FRAME2) {
state->pls.es.frame |= MSG_ReadByte (net_message) << 8;

Some files were not shown because too many files have changed in this diff Show more