MCPcopy Create free account
hub / github.com/ZDoom/Raze / ConstructSections

Function ConstructSections

source/core/rendering/hw_sections.cpp:560–665  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

558//==========================================================================
559
560static void ConstructSections(TArray<sectionbuildsector>& builders)
561{
562 // count all sections and allocate the global buffers.
563 TArray<int> splitwalls;
564
565 // Allocate all Section walls.
566 sectionLines.Resize(wall.Size() + splits.Size() * 2 / 3);
567
568 for (unsigned i = 0; i < splits.Size(); i++)
569 {
570 if (i % 3) splitwalls.Push(splits[i]);
571 }
572
573 unsigned nextwall = wall.Size();
574 for (unsigned i = 0; i < wall.Size(); i++)
575 {
576 sectionLines[i].startpoint = i;
577 sectionLines[i].endpoint = wall[i].point2;
578 sectionLines[i].wall = i;
579 sectionLines[i].partner = wall[i].nextwall;
580 }
581 for (unsigned i = wall.Size(); i < sectionLines.Size(); i++)
582 {
583 unsigned pair = (i - wall.Size());
584 sectionLines[i].startpoint = splitwalls[pair];
585 sectionLines[i].endpoint = splitwalls[pair ^ 1];
586 sectionLines[i].wall = -1;
587 sectionLines[i].partner = wall.Size() + (pair ^ 1);
588 }
589
590 unsigned count = 0;
591 // allocate as much as possible from the arena here.
592 size_t size = sizeof(*sectionsPerSector.Data()) * sector.Size();
593 auto data = sectionArena.Calloc(size);
594 sectionsPerSector.Set(static_cast<decltype(sectionsPerSector.Data())>(data), sector.Size());
595
596 for (unsigned i = 0; i < sector.Size(); i++)
597 {
598 auto& builder = builders[i];
599 count += builder.sections.Size();
600
601 size = sizeof(int) * builder.sections.Size();
602 data = sectionArena.Calloc(size);
603 sectionsPerSector[i].Set(static_cast<int* >(data), builder.sections.Size()); // although this may need reallocation, it is too small to warrant single allocations for each sector.
604 }
605 sections.Resize(count); // this we cannot put into the arena because its size may change.
606 memset(sections.Data(), 0, count * sizeof(*sections.Data()));
607
608 // now fill in the data
609
610 int cursection = 0;
611 for (unsigned i = 0; i < sector.Size(); i++)
612 {
613 auto& builder = builders[i];
614 for (unsigned j = 0; j < builder.sections.Size(); j++)
615 {
616 auto section = &sections[cursection];
617 auto& srcsect = builder.sections[j];

Callers 1

hw_CreateSectionsFunction · 0.85

Calls 8

CallocMethod · 0.80
ShrinkToFitMethod · 0.80
ResizeMethod · 0.45
SizeMethod · 0.45
PushMethod · 0.45
DataMethod · 0.45
SetMethod · 0.45
FindMethod · 0.45

Tested by

no test coverage detected