From e62b64bac8cb1b51abf679a499d8aaa61abb73ac Mon Sep 17 00:00:00 2001 From: FSCyborg Date: Sun, 10 Nov 2019 00:55:11 -0500 Subject: [PATCH 1/2] Fix Dumb_Rotate Regression Allows jump nodes to use instrinsic/dumb rotation again by exposing the jump node class to the model instancing code and adding a check for it in modelread. --- code/jumpnode/jumpnode.cpp | 47 ++++++++++++++++++++++++++++++++++---- code/jumpnode/jumpnode.h | 3 +++ code/model/modelrender.cpp | 12 +++++++--- 3 files changed, 55 insertions(+), 7 deletions(-) diff --git a/code/jumpnode/jumpnode.cpp b/code/jumpnode/jumpnode.cpp index 16e258c80f..1e643834e0 100644 --- a/code/jumpnode/jumpnode.cpp +++ b/code/jumpnode/jumpnode.cpp @@ -32,7 +32,8 @@ CJumpNode::CJumpNode() : m_radius(0.0f), m_modelnum(-1), m_objnum(-1), m_flags(0 /** * Constructor for CJumpNode class, with world position argument */ -CJumpNode::CJumpNode(vec3d *position) : m_radius(0.0f), m_modelnum(-1), m_objnum(-1), m_flags(0) +CJumpNode::CJumpNode(vec3d* position) + : m_radius(0.0f), m_modelnum(-1), m_objnum(-1), m_flags(0) { Assert(position != NULL); @@ -43,10 +44,18 @@ CJumpNode::CJumpNode(vec3d *position) : m_radius(0.0f), m_modelnum(-1), m_objnum // Set m_modelnum and m_radius m_modelnum = model_load(NOX("subspacenode.pof"), 0, NULL, 0); - if (m_modelnum == -1) + if (m_modelnum == -1) { Warning(LOCATION, "Could not load default model for %s", m_name); - else + } else { m_radius = model_get_radius(m_modelnum); + + // set up animation in case of instrinsic_rotate + polymodel* pm = model_get(m_modelnum); + + if (pm->flags & PM_FLAG_HAS_INTRINSIC_ROTATE) { + m_polymodel_instance_num = model_create_instance(false, m_modelnum); + } + } m_pos.xyz.x = position->xyz.x; m_pos.xyz.y = position->xyz.y; @@ -59,11 +68,12 @@ CJumpNode::CJumpNode(vec3d *position) : m_radius(0.0f), m_modelnum(-1), m_objnum } CJumpNode::CJumpNode(CJumpNode&& other) SCP_NOEXCEPT - : m_radius(other.m_radius), m_modelnum(other.m_modelnum), m_objnum(other.m_objnum), m_flags(other.m_flags) + : m_radius(other.m_radius), m_modelnum(other.m_modelnum), m_objnum(other.m_objnum), m_polymodel_instance_num(other.m_polymodel_instance_num), m_flags(other.m_flags) { other.m_radius = 0.0f; other.m_modelnum = -1; other.m_objnum = -1; + other.m_polymodel_instance_num = -1; other.m_flags = 0; m_display_color = other.m_display_color; @@ -80,11 +90,13 @@ CJumpNode& CJumpNode::operator=(CJumpNode&& other) SCP_NOEXCEPT m_modelnum = other.m_modelnum; m_objnum = other.m_objnum; m_flags = other.m_flags; + m_polymodel_instance_num = other.m_polymodel_instance_num; other.m_radius = 0.0f; other.m_modelnum = -1; other.m_objnum = -1; other.m_flags = 0; + other.m_polymodel_instance_num = -1; m_display_color = other.m_display_color; m_pos = other.m_pos; @@ -162,6 +174,14 @@ vec3d *CJumpNode::GetPosition() return &m_pos; } +/* +* @return Polymodel Instance Index +*/ +int CJumpNode::GetPolymodelInstanceNum() +{ + return m_polymodel_instance_num; +} + // Settor functions for private variables /** @@ -331,6 +351,7 @@ void CJumpNode::Render(model_draw_list* scene, vec3d *pos, vec3d *view_pos) model_render_params render_info; + render_info.set_object_number(m_objnum); render_info.set_detail_level_lock(0); render_info.set_flags(mr_flags); @@ -392,6 +413,24 @@ CJumpNode *jumpnode_get_by_name(const char* name) return NULL; } +/** + * Get jump node object by the object number + * + * @param objnum to search for + * @return Jump node object pointer + */ +CJumpNode *jumpnode_get_by_objnum(int objnum) +{ + Assert(objnum > -1); + + for (CJumpNode &jnp : Jump_nodes) { + if (jnp.GetSCPObjectNumber() == objnum) + return &(jnp); + } + + return nullptr; +} + /** * Given an object, returns which jump node it's inside (if any) * diff --git a/code/jumpnode/jumpnode.h b/code/jumpnode/jumpnode.h index b6386cab33..8d8dbbcc15 100644 --- a/code/jumpnode/jumpnode.h +++ b/code/jumpnode/jumpnode.h @@ -36,6 +36,7 @@ private: int m_modelnum; int m_objnum; // objnum of this jump node + int m_polymodel_instance_num {-1}; // polymodel instance number, used for rotations int m_flags; color m_display_color; // Color node will be shown in (Default:0/255/0/255) @@ -58,6 +59,7 @@ public: char *GetName(); int GetModelNumber(); int GetSCPObjectNumber(); + int GetPolymodelInstanceNum(); object *GetSCPObject(); color GetColor(); vec3d *GetPosition(); @@ -83,6 +85,7 @@ extern SCP_list Jump_nodes; //-----Functions----- CJumpNode *jumpnode_get_by_name(const char *name); +CJumpNode *jumpnode_get_by_objnum(int objnum); CJumpNode *jumpnode_get_which_in(object *objp); void jumpnode_render_all(); diff --git a/code/model/modelrender.cpp b/code/model/modelrender.cpp index 75c79f3867..dbb8d8c11c 100644 --- a/code/model/modelrender.cpp +++ b/code/model/modelrender.cpp @@ -19,6 +19,7 @@ #include "graphics/light.h" #include "graphics/uniforms.h" #include "io/timer.h" +#include "jumpnode/jumpnode.h" #include "math/staticrand.h" #include "mod_table/mod_table.h" #include "model/modelrender.h" @@ -2628,12 +2629,17 @@ void model_render_queue(model_render_params* interp, model_draw_list* scene, int pmi = model_get_instance(shipp->model_instance_num); } else if (pm->flags & PM_FLAG_HAS_INTRINSIC_ROTATE) { - if (objp->type == OBJ_ASTEROID) + if (objp->type == OBJ_ASTEROID) { pmi = model_get_instance(Asteroids[objp->instance].model_instance_num); - else if (objp->type == OBJ_WEAPON) + } else if (objp->type == OBJ_WEAPON) { pmi = model_get_instance(Weapons[objp->instance].model_instance_num); - else + } else if (objp->type == OBJ_JUMP_NODE) { + CJumpNode* jnp = jumpnode_get_by_objnum(objnum); + Assertion(jnp != nullptr, "Could not find jump node with object number %d!", objnum); + pmi = model_get_instance(jnp->GetPolymodelInstanceNum()); + } else { Warning(LOCATION, "Unsupported object type %d for rendering intrinsic-rotate submodels!", objp->type); + } } } From 2238c0af63504e11c0cd89b0bad43ba715380f27 Mon Sep 17 00:00:00 2001 From: FSCyborg Date: Tue, 12 Nov 2019 16:58:41 -0500 Subject: [PATCH 2/2] Move Default Values to Class Define Part of modernizing the code base, Travis, at least, prefers defaults to be in the class definition instead of having multiple constructor functions have the same default values. --- code/jumpnode/jumpnode.cpp | 3 +-- code/jumpnode/jumpnode.h | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/code/jumpnode/jumpnode.cpp b/code/jumpnode/jumpnode.cpp index 1e643834e0..810ebdd5a6 100644 --- a/code/jumpnode/jumpnode.cpp +++ b/code/jumpnode/jumpnode.cpp @@ -18,7 +18,7 @@ SCP_list Jump_nodes; /** * Constructor for CJumpNode class, default */ -CJumpNode::CJumpNode() : m_radius(0.0f), m_modelnum(-1), m_objnum(-1), m_flags(0) +CJumpNode::CJumpNode() { gr_init_alphacolor(&m_display_color, 0, 255, 0, 255); @@ -33,7 +33,6 @@ CJumpNode::CJumpNode() : m_radius(0.0f), m_modelnum(-1), m_objnum(-1), m_flags(0 * Constructor for CJumpNode class, with world position argument */ CJumpNode::CJumpNode(vec3d* position) - : m_radius(0.0f), m_modelnum(-1), m_objnum(-1), m_flags(0) { Assert(position != NULL); diff --git a/code/jumpnode/jumpnode.h b/code/jumpnode/jumpnode.h index 8d8dbbcc15..83d11188c3 100644 --- a/code/jumpnode/jumpnode.h +++ b/code/jumpnode/jumpnode.h @@ -32,13 +32,13 @@ class CJumpNode { private: char m_name[NAME_LENGTH]; - float m_radius; + float m_radius {0.0f}; - int m_modelnum; - int m_objnum; // objnum of this jump node + int m_modelnum {-1}; + int m_objnum {-1}; // objnum of this jump node int m_polymodel_instance_num {-1}; // polymodel instance number, used for rotations - int m_flags; + int m_flags {0}; color m_display_color; // Color node will be shown in (Default:0/255/0/255) vec3d m_pos;