persona-3-dual
A DS demake of Persona 3
Loading...
Searching...
No Matches
Environment Class Reference

#include <Environment.hpp>

Collaboration diagram for Environment:

Public Member Functions

 Environment ()
 Constructs an empty Environment with all texture and display-list slots cleared and no database entry attached.
bool load (const EnvironmentDbEntry *entry, std::array< const unsigned int *, MAX_ENVIRONMENT_TEXTURES > bitmaps)
 Loads environment geometry (display lists) and textures from the compiled .bin file described by an EnvironmentDbEntry.
void draw ()
 Renders every loaded texture/display-list pair for the currently loaded environment.
void drawBillboards (bool faceCamera, ae::q20_12_t camX, ae::q20_12_t camY, ae::q20_12_t camZ)
 Renders every billboard quad defined for the currently loaded environment.
void cleanup ()
 Frees all display lists and deletes all textures owned by this Environment, and clears the current database entry.

Private Attributes

const EnvironmentDbEntry * dbEntry
u32 * displayLists [MAX_ENVIRONMENT_TEXTURES]
u32 dlSizes [MAX_ENVIRONMENT_TEXTURES]
int textureIDs [MAX_ENVIRONMENT_TEXTURES]
MathManager & math = MathManager::getInstance()
RenderManager & render = RenderManager::getInstance()

Detailed Description

Definition at line 14 of file Environment.hpp.

Constructor & Destructor Documentation

◆ Environment()

Environment::Environment ( )

Constructs an empty Environment with all texture and display-list slots cleared and no database entry attached.

Definition at line 10 of file Environment.cpp.

Member Function Documentation

◆ cleanup()

void Environment::cleanup ( )

Frees all display lists and deletes all textures owned by this Environment, and clears the current database entry.

Safe to call at any time, including when no environment is loaded

Note
Always sweeps the full fixed-size arrays rather than looping to dbEntry->textureCount. Looping to the current entry's count would mean a load() that failed partway through (or a room with fewer texture slots than the one loaded before it) could leave stale, un-freed pointers sitting past that count, silently leaking memory and VRAM texture slots across room transitions.

Definition at line 187 of file Environment.cpp.

Here is the caller graph for this function:

◆ draw()

void Environment::draw ( )

Renders every loaded texture/display-list pair for the currently loaded environment.

Does nothing if no environment is currently loaded (dbEntry is null). Skips any texture slot that has no bound texture ID, and skips the draw call itself (but still binds the texture) if that slot has no display list, guarding against corrupted or missing display-list pointers.

Definition at line 144 of file Environment.cpp.

◆ drawBillboards()

void Environment::drawBillboards ( bool faceCamera,
ae::q20_12_t camX,
ae::q20_12_t camY,
ae::q20_12_t camZ )

Renders every billboard quad defined for the currently loaded environment.

Note
Batches consecutive billboards that share a texture slot into a single glBegin/glEnd(GL_QUADS) block. Does nothing if no environment is loaded or it has no billboards. Any billboard referencing an out-of-range or unbound texture slot is skipped.
Parameters
faceCameraIf true, each billboard's right vector is recomputed every call so it always faces the given camera position (classic screen-facing billboarding). If false, billboards use a fixed world-axis-aligned orientation.
camXWorld-space X coordinate of the camera, used only when faceCamera is true.
camYWorld-space Y coordinate of the camera (unused. billboards only rotate about the Y axis).
camZWorld-space Z coordinate of the camera, used only when faceCamera is true.

Definition at line 162 of file Environment.cpp.

◆ load()

bool Environment::load ( const EnvironmentDbEntry * entry,
std::array< const unsigned int *, MAX_ENVIRONMENT_TEXTURES > bitmaps )

Loads environment geometry (display lists) and textures from the compiled .bin file described by an EnvironmentDbEntry.

Always begins with a hard reset (cleanup()) of any previously loaded state, so this is safe to call repeatedly across room transitions without leaking display lists or texture slots. On any failure the partially loaded state is cleaned up again before returning.

Parameters
entryPointer to the database entry describing this environment (name, texture metadata/count, binary file name). Must be non-null and have textureCount <= MAX_ENVIRONMENT_TEXTURES, otherwise this fails immediately.
bitmapsArray of raw bitmap pointers, one per texture slot, to be uploaded to VRAM. Max size of MAX_ENVIRONMENT_TEXTURES. May be null, or contain null entries, in which case the corresponding texture slot(s) are skipped.
Returns
true if the binary file was opened, validated, and fully loaded (display lists and textures); false if entry was invalid, the file could not be opened or failed magic/size validation, or an allocation failed while reading display list data.
Note
entry->binaryFile is a build-time string baked in by obj2environment.py. It cannot know the runtime fat/SD mount root, so it must be combined with fatBasePath before fopen() can find it. ASSUMPTION: binaryFile already contains the full "environments/<name>/" relative path. If the printed path below is missing that folder, binaryFile is actually the bare filename and this needs to be fatBasePath + "environments/" + entry->name + "/" + entry->binaryFile instead. Check environmentDb.cpp's entry to confirm behaviour.

Definition at line 20 of file Environment.cpp.

Here is the call graph for this function:

Member Data Documentation

◆ dbEntry

const EnvironmentDbEntry* Environment::dbEntry
private

Definition at line 107 of file Environment.hpp.

◆ displayLists

u32* Environment::displayLists[MAX_ENVIRONMENT_TEXTURES]
private

Definition at line 109 of file Environment.hpp.

◆ dlSizes

u32 Environment::dlSizes[MAX_ENVIRONMENT_TEXTURES]
private

Definition at line 110 of file Environment.hpp.

◆ math

MathManager& Environment::math = MathManager::getInstance()
private

Definition at line 113 of file Environment.hpp.

◆ render

RenderManager& Environment::render = RenderManager::getInstance()
private

Definition at line 114 of file Environment.hpp.

◆ textureIDs

int Environment::textureIDs[MAX_ENVIRONMENT_TEXTURES]
private

Definition at line 111 of file Environment.hpp.


The documentation for this class was generated from the following files: