]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - zone.c
implemented zpass shadowing, not used yet
[xonotic/darkplaces.git] / zone.c
diff --git a/zone.c b/zone.c
index 0bb325385f1ded23fe763e170f93bdadeb954bde..417a290a6fd1a7b6cf97e087092a77a818f9504b 100644 (file)
--- a/zone.c
+++ b/zone.c
@@ -393,7 +393,7 @@ void Mem_ExpandableArray_FreeArray(memexpandablearray_t *l)
        size_t i;
        if (l->maxarrays)
        {
-               for (i = 0;i != l->numarrays;l++)
+               for (i = 0;i != l->numarrays;i++)
                        Mem_Free(l->arrays[i].data);
                Mem_Free(l->arrays);
        }
@@ -411,7 +411,7 @@ void *Mem_ExpandableArray_AllocRecord(memexpandablearray_t *l)
                        {
                                memexpandablearray_array_t *oldarrays = l->arrays;
                                l->maxarrays = max(l->maxarrays * 2, 128);
-                               l->arrays = Mem_Alloc(l->mempool, l->maxarrays * sizeof(*l->arrays));
+                               l->arrays = (memexpandablearray_array_t*) Mem_Alloc(l->mempool, l->maxarrays * sizeof(*l->arrays));
                                if (oldarrays)
                                {
                                        memcpy(l->arrays, oldarrays, l->numarrays * sizeof(*l->arrays));
@@ -419,7 +419,7 @@ void *Mem_ExpandableArray_AllocRecord(memexpandablearray_t *l)
                                }
                        }
                        l->arrays[i].numflaggedrecords = 0;
-                       l->arrays[i].data = Mem_Alloc(l->mempool, (l->recordsize + 1) * l->numrecordsperarray);
+                       l->arrays[i].data = (unsigned char *) Mem_Alloc(l->mempool, (l->recordsize + 1) * l->numrecordsperarray);
                        l->arrays[i].allocflags = l->arrays[i].data + l->recordsize * l->numrecordsperarray;
                        l->numarrays++;
                }
@@ -431,6 +431,7 @@ void *Mem_ExpandableArray_AllocRecord(memexpandablearray_t *l)
                                {
                                        l->arrays[i].allocflags[j] = true;
                                        l->arrays[i].numflaggedrecords++;
+                                       memset(l->arrays[i].data + l->recordsize * j, 0, l->recordsize);
                                        return (void *)(l->arrays[i].data + l->recordsize * j);
                                }
                        }
@@ -438,7 +439,16 @@ void *Mem_ExpandableArray_AllocRecord(memexpandablearray_t *l)
        }
 }
 
-void Mem_ExpandableArray_FreeRecord(memexpandablearray_t *l, void *record)
+/*****************************************************************************
+ * IF YOU EDIT THIS:
+ * If this function was to change the size of the "expandable" array, you have
+ * to update r_shadow.c
+ * Just do a search for "range =", R_ShadowClearWorldLights would be the first
+ * function to look at. (And also seems like the only one?) You  might have to
+ * move the  call to Mem_ExpandableArray_IndexRange  back into for(...) loop's
+ * condition
+ */
+void Mem_ExpandableArray_FreeRecord(memexpandablearray_t *l, void *record) // const!
 {
        size_t i, j;
        unsigned char *p = (unsigned char *)record;
@@ -458,6 +468,33 @@ void Mem_ExpandableArray_FreeRecord(memexpandablearray_t *l, void *record)
        }
 }
 
+size_t Mem_ExpandableArray_IndexRange(const memexpandablearray_t *l)
+{
+       size_t i, j, k, end = 0;
+       for (i = 0;i < l->numarrays;i++)
+       {
+               for (j = 0, k = 0;k < l->arrays[i].numflaggedrecords;j++)
+               {
+                       if (l->arrays[i].allocflags[j])
+                       {
+                               end = l->numrecordsperarray * i + j + 1;
+                               k++;
+                       }
+               }
+       }
+       return end;
+}
+
+void *Mem_ExpandableArray_RecordAtIndex(const memexpandablearray_t *l, size_t index)
+{
+       size_t i, j;
+       i = index / l->numrecordsperarray;
+       j = index % l->numrecordsperarray;
+       if (i >= l->numarrays || !l->arrays[i].allocflags[j])
+               return NULL;
+       return (void *)(l->arrays[i].data + j * l->recordsize);
+}
+
 
 // used for temporary memory allocations around the engine, not for longterm
 // storage, if anything in this pool stays allocated during gameplay, it is
@@ -531,10 +568,21 @@ void MemStats_f(void)
 {
        Mem_CheckSentinelsGlobal();
        R_TextureStats_Print(false, false, true);
+       GL_Mesh_ListVBOs(false);
        Mem_PrintStats();
 }
 
 
+char* Mem_strdup (mempool_t *pool, const char* s)
+{
+       char* p;
+       size_t sz = strlen (s) + 1;
+       if (s == NULL) return NULL;
+       p = (char*)Mem_Alloc (pool, sz);
+       strlcpy (p, s, sz);
+       return p;
+}
+
 /*
 ========================
 Memory_Init