MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / EBNode_AddEdge

Function EBNode_AddEdge

editor/ebnode.cpp:862–922  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

860}
861
862void EBNode_AddEdge(int spnt, int sroom, int epnt, int eroom, bool f_add_reverse, float computed_max_rad) {
863 int i;
864
865 BNode_verified = false;
866
867 // Make sure there are no zero length paths
868 if (sroom == eroom && spnt == epnt) {
869 return;
870 }
871
872 bn_list *snlist;
873 snlist = BNode_GetBNListPtr(sroom);
874 bn_list *enlist;
875 enlist = BNode_GetBNListPtr(eroom);
876
877 ASSERT(snlist && enlist);
878
879 bool f_exists = false;
880
881 // Check to see if this edge already exists
882 for (i = 0; i < snlist->nodes[spnt].num_edges; i++) {
883 if (snlist->nodes[spnt].edges[i].end_index == epnt && snlist->nodes[spnt].edges[i].end_room == eroom) {
884 f_exists = true;
885 break;
886 }
887 }
888
889 if (!f_exists) {
890 int new_edge;
891
892 // Makes sure that if there are no edges, then the edge pointer is NULL and that if
893 // there are edges that the edge pointer isn't NULL
894 ASSERT(!((snlist->nodes[spnt].num_edges == 0) ^ (snlist->nodes[spnt].edges == NULL)));
895
896 new_edge = snlist->nodes[spnt].num_edges;
897 snlist->nodes[spnt].num_edges++;
898
899 if (new_edge == 0) {
900 snlist->nodes[spnt].edges = (bn_edge *)mem_malloc(sizeof(bn_edge));
901 } else {
902 snlist->nodes[spnt].edges =
903 (bn_edge *)mem_realloc(snlist->nodes[spnt].edges, sizeof(bn_edge) * snlist->nodes[spnt].num_edges);
904 }
905
906 float cost = vm_VectorDistance(&snlist->nodes[spnt].pos, &enlist->nodes[epnt].pos);
907 if (cost < 1.0f)
908 cost = 1.0f;
909
910 snlist->nodes[spnt].edges[new_edge].cost = (cost < 32767.0f) ? (int16_t)cost : (int16_t)32767;
911 snlist->nodes[spnt].edges[new_edge].end_index = epnt;
912 snlist->nodes[spnt].edges[new_edge].end_room = BOA_INDEX(eroom);
913 snlist->nodes[spnt].edges[new_edge].flags = 0;
914
915 if (f_add_reverse) {
916 snlist->nodes[spnt].edges[new_edge].max_rad = EBNode_DetermineMaxSizeForEdge(spnt, sroom, epnt, eroom);
917 EBNode_AddEdge(epnt, eroom, spnt, sroom, false, snlist->nodes[spnt].edges[new_edge].max_rad);
918 } else {
919 snlist->nodes[spnt].edges[new_edge].max_rad = computed_max_rad;

Callers 7

OnAinMakeEdgeMethod · 0.85
EBNode_VerifyGraphFunction · 0.85
EBNode_InsertNodeOnEdgeFunction · 0.85
EBNode_AutoEdgeNodeFunction · 0.85

Calls 3

BNode_GetBNListPtrFunction · 0.85
vm_VectorDistanceFunction · 0.50

Tested by

no test coverage detected