Hi,
I don't have any clue of the opengl and simgear based stuff, so I looked only
at the struct Building and how to optimize that.
In the attachment you can find 3 structs representing the data.
The original is yours.
'small' is a very small optimization that doesn't require you to map floats to
discrete values. The flags variable holds bool pitched and the building type. I
assumed floors not to be bigger than 65k, so I reduced it to 16 bit ;).
In 'aggressive' I replaced the floats which I think doesn't require the full 4
byte precision of a float. However the mapping from float->int int->float can
take much time depending on the translation function you use. If normal float
division/multiplication is too slow, you could write some functions to directly
accessing the float (shifting the "fraction" depending on the exponent)
(http://en.wikipedia.org/wiki/Single_precision ).
However just ideas on that struct. Sizes in bytes:
original: 44
small: 36
aggressive: 28
Regards,
scosu
On 23.05.2012 11:37, Stuart Buchanan wrote:
> Hi All,
>
> Emilian and Vivian have pointed out a problem with the random
> buildings - they gobble memory. I'd like to get some advice on
> whether there's any solution, and also to ask someone with more C++
> knowledge than myself to take a look at the code and check I'm not
> doing something stupid.
>
> The specific problem scenario is starting a KLAX (Los Angeles) which
> is in the middle of a massive urban area.
>
> Using the default random building density, the tiles that are loaded
> initially when sitting on the runway generates ~ 340k random
> buildings. Each building consists of between 9 and 12 quads (we have a
> "basement" at the bottom to handle slopes, 4 walls, and a roof which
> may be pitched). In turn, each quad has 4 corners, each of which has
> a position (vec3), a normal (vec3) and a texture coordinate (vec2).
>
> So, the absolute minimum memory occupancy of the data for the random
> buildings is 340k * 10 * 4 * 8 = 108MB. On top of that will be some
> OSG overhead and the building texture itself.
>
> Once you start flying more tiles are loaded (presumably well before
> any old tiles are unloaded?) so memory occupancy rapidly increases.
> Flying east from KLAX is particularly bad.
>
> Using a higher building density makes the problem much worse, as you
> need 4X the number of buildings to get double the linear density. I
> ran out of memory on a 4GB system pretty quickly (and tile loading
> takes an age - something I need to look at again).
>
> So
> - Does anyone have any bright ideas on what I can do to reduce the
> base memory occupancy? One option might be to not generate the
> "basement" if the terrain is level.
> - Could a fresh pair of eyes take a look at the obj.cxx, mat.cxx and
> SGBuildingBin.[ch]xx code to see if I've missed something obvious.
>
> Thanks,
>
> -Stuart
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Flightgear-devel mailing list
> Flightgear-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/flightgear-devel
#include <stdint.h>
#include <stdio.h>
enum BuildingType {
SMALL = 0,
MEDIUM,
LARGE
};
struct building_original {
enum BuildingType type;
float position[3];
float width;
float depth;
float height;
int floors;
float rotation;
bool pitched;
float radius;
};
#define BUILDING_FLAGS_SMALL 0x01
#define BUILDING_FLAGS_MEDIUM 0x02
#define BUILDING_FLAGS_LARGE 0x04
#define BUILDING_FLAGS_PITCHED 0x08
struct building_small {
uint16_t flags;
uint16_t floors;
float position[3];
float width;
float depth;
float height;
float rotation;
float radius;
};
#pragma pack(push,1)
struct building_aggressive {
float position[3];
uint16_t width;
uint16_t depth;
uint16_t height;
uint16_t rotation;
uint16_t floors;
uint8_t alignment_no_data; // to get better access times for variable radius
uint8_t flags;
uint32_t radius;
};
#pragma pack(pop)
int main(void) {
printf("original: %lu\n", sizeof(struct building_original));
printf("small: %lu\n", sizeof(struct building_small));
printf("aggressive: %lu\n", sizeof(struct building_aggressive));
}
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel