// This file is part of ClassicAPI.
//
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
// of the GNU General Public License as published by the Free Software Foundation, either
// version 3 of the License, or (at your option) any later version.
//
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with
// ClassicAPI. If not, see .
// A ModelScene's terrain (scene:SetWorldTerrain, a ClassicAPI extension;
// research in docs/notes/model-scene.md "Extension 9").
//
// The chunks are the world's CMapChunk objects, owned by the scene, built
// and drawn by the world's own functions:
//
// - Load. The ADT is read whole into the scene's buffer and its MHDR read
// as ParseAreaFile (0x006C2010) reads it. The tile's textures load into
// an area stand-in through LoadAreaTextures, which touches only the
// texture slots. Each chunk is constructed by CMapChunk's constructor
// and gets CreateAreaChunk's fields (0x006C2880) and the self-contained
// steps of CMapChunk::Load (0x006AF5F0) in its order: record fixup,
// header fields, vertices, normals, the impassable flag, layers, shadow
// texture, combined texture, flags. Load's other steps write world
// state and are left out: LinkNeighbours reads the global area table
// (the scene links its own chunks by the same rule), LoadReferences
// makes doodad and map object defs in the world's hashes, LinkLights
// takes the world's map lights, and the area is never filed in the
// global table. Liquids and sound emitters (a null callback in 1.12)
// are left out too.
// - Buffers. The world's chunk buffer pool is freed and rebuilt on a far
// clip change and a map unload (CreateChunkBufferPool 0x006AE640), and
// only the world's listed chunks give theirs back first. The scene's
// chunks take their buffers from a static pool of their own, made as
// the world makes its pool; SelectMesh goes to the world's pool only for
// a buffer of the device's dynamic pool (usage 2).
// - Draw. DrawChunkPass (0x00684510) for each chunk the scene's view
// shows: the chunk level and view depth (0x006AFAD0), the box against
// the scene's volume (CullSceneChunks 0x00683BF0, without the horizon),
// the world transform at the chunk less the eye, a lighting record at
// the chunk's centre with the scene's lights there, the fog and, nearer
// than the fog end by twice the radius, the light (the chunk's slots
// 0x006C0CC0: the scene light stands in for the sun, the scene fog for
// the zone's), then SelectMesh. DrawLayers reads the camera and the fog
// end from world globals, so both hold the scene's values while it draws.
// - Settings. A chunk's textures are made for the shader flags, the
// shadowLevel and the map shadows flag it was built with; when any
// changes (a world loads after the glue screen), the chunks are built
// again from the kept files.
#include "model/Scene.h"
#include "Game.h"
#include "Offsets.h"
#include "dbc/Lookup.h"
#include "gx/Device.h"
#include "gx/Matrix.h"
#include "model/M2.h"
#include "model/SceneContact.h"
#include "model/SceneFile.h"
#include
#include
#include
#include
#include
#include
#include