Repository navigation
Event System
How scripted scenes run: the event manager and its sub-managers, the BDAT tables that describe each event, the command sequencer, the script commands (camera, character, effect, text), skipping and scrubbing, facial animation, depth of field, and how events connect to the game layer and to field gimmicks (Field-Gimmicks). Namespace event, folders src/application/BF2/event/ (E/ below), plugin/ (P/), rcha/ (R/), plus gf/game/event/ (GE/) and gf/data/ (GD/). Reading guide: Home. Snapshot: main at commit a313ecb66.
Coverage. About 5,465 of 5,741 event and gmk functions are matched. The big gaps in this area are the event manager's constructor and the body of the event loop (SeqManager::exec::update), the scene setup and start functions, the frame manager's update and the character command updates. They are listed at the end. Members named unknownXX carry inferred roles; the page says "inferred" when it leans on one.
-
event::Managerowns up to 64 sub-managers (FixedVector<IManager*, 64>) and forwards each phase to all of them (Manager::execMessage(MSG_TYPE)). There are 54IManagersubclasses: camera, character, object, frame, skip, text, todo (undo/redo), sequencer, resource, depth of field, environment, hide, quest, status, voice, BGM, SE, volume, movie, UI and others (E/*_manager.h). The constructor that registers them is not decompiled yet. -
Phases broadcast to every sub-manager (
MSG_TYPE,E/i_manager.h; values 1 to 4 and the stop/clear pairs are visible inManager, the other labels are inferred from use): init begin (1), init load (3), init (4), setup scene (5), setup scene end (6), start scene (7), start page (8), end scene begin (9), end scene (10), stop (11), clear (12), clear post (13), update (14), update post (15), render (16), render post (17), tail (18), tail post (19). -
Manager::updatesends 14 then 15. When the sequencer's front command is the "play next" command, it sends 12 and 13 and callsclear(); if the sequencer reports a script load error (flag bit 0), the event ends with message 2.Manager::end()sends 11 once and returns false while the init-state bit 0 is set. -
Memory and time. The event memory pool is
0x2300000bytes (35 MiB) named "GfTalk", created inGfGameEvent::initialize. Event time runs at 30 frames per second (Manager::drawInfocomputes minutes asframe / 1800and seconds asframe % 1800 / 30).Manager::bkgHomeMenupauses the CPU manager while the HOME menu is open. - Event scripts are
.sbfiles named after the event (Manager::failureSkipprintsfailure skip!! [<name>.sb]).play_startcreates script slot 2 from that name (SCOM_SCRIPT::create(2, name, false)) and raises the error flag if loading fails. -
File suffixes the event resource helper appends (
Extend,E/extend.cpp):.wimdomodels,.arc,.anm,.evaand_eff.evaanimations,.wiefbeffects and_pack.wiefb,.wilgtlights,.nopand.acbaudio,.lipand.wiliplip-sync,.evpaevent packs,.sar,.webmmovies.ResManagerholds up to 512 items with up to 96 listeners each; a pack (.evpa) is loaded throughfw::RenderResource::requestand normal loading is held back while a pack loads.
-
Lookup.
SeqInfo::setup(id)(E/seq_info.cpp) iterates theEVT_listListsheet, reads the columnlistSeat(a sheet name per row), opens that sheet and finds the row whose id range contains the event id, then readsevtName. If the row'slinkIDis non-zero (and the event is not debug-played once),GfGameEvent::playappends_linkto the event name. -
Event id ranges (
GfDataEvent,GD/gf_data_event.cpp): scenario events start at 10001 (604 ids), Blade-creation events at 19001 (58), Blade-quest events at 20707 (504). The event lists are the BDAT sheetsEVT_LIST_BF,_BL,_QST01,_FEV01and_TLK01. Save-worthy scenario events are a hard-coded list of about 230 ids (10001 to 10494). -
Played flag. When the "event play end" notice fires,
GfGameFlag::setLocal(1, 0x8a5f + index, 1)records that the event was played (up to 2000 flags, 100 per list); the index formula as written looks odd (top - event + list * 100) and is not explained. See Save-Data for the flag store. -
Per-event columns read by
SeqInfo::setup: state changes (chgStID,chgEdID),category, text (mstxt,text),weather,clock,clockStop,cloud; fades (opFadeOutEnable,opFadeOut,opFadeWait,opFadeInEnable,opFadeIn,opFadeColR/G/Band theed*set); formations and BGM (stFormID,edFormID,opBgm,edBgm); hiding (hideNpc,hideEne,hideMob,hideMap); "outsiders" (outsiderOpt,outsiderEnable,outsiderType,outsiderX/Y/Z/R); chaining (nextID,linkID) and misc (jijiDisp,wpnDisp,colFilterNear,colFilterFar,voice). Optional, only when the column exists:nextIDtheater,envSeam,evtLight,hood(default 1),cssnd,centerForm,centerID,centerX/Y/Z,centerR(degrees, converted to radians). If the manager asks for a forced end fade and the row has none, the end fade becomes: out time 20, wait 0, black. -
Categories. The
categorycolumn indexesNONE, TEV, FEV, SEV, CS, MOV(0 to 5). Category 4 (a cutscene) mutes the SE categories with a 0.5 s fade while it plays (GfGameEvent::updateCsEventCategoryVolume). Category 1 does not freeze the field; other categories freeze game-object layers 3, 4 and 10 (ignoring event objects) and set event speed layer 1 to 0 (GfGameEvent::eventPlayerOff). Category 5 is inferred to be "capture" (SeqManager::checkCapturetests the linked event's category).
SeqManager (E/seq_manager.cpp) runs a CmdQueue<32> of commands. Each command returns wait (0), done (1) or next (2, run the following commands in parallel) (CmdQueue::update, E/cmd_queue.h); the queue drops its oldest item when full. The phases are fields of SeqManager:
-
Start side:
play_start,play_next,start,start_fadeout,start_areajump,start_notice,start_loading,start_other,start_form,start_change,start_env_seam,start_weather,start_streaming0/1,start_capture_wait. -
Body and end side:
exec,exec_fadeout,exec_grass,end_change,end_eff,end_stream,end_wait,end_areajump,end_env_seam,end_fadewait,end_fadein,end_notice,end.
What the matched phase commands do:
-
start_notice,end_noticeandend_waitcallGfEvent::callEventPlaywith the codes "event end wait" (8), "event end" (9) and "event play end" (10): the game layer is told through them (see below). -
start_othercreates "other%d" and "other_bl%d" copies of party drivers and Blades 1 to 3 when the object manager has fewer characters than requested, and waits for them to load. -
start_weatherappliesclock,clockStop, andweather/cloudonly when greater than 0 toEnvManager. -
start_streaming0(category 2 or above) reads the first seam point (seamless), then waits for movies, models and motions, and the CS sound to load unless fast skip is active. It waits at least 2 frames for capture events and while the seam map is reading or middle textures stream (each capped at 900 frames) and, if a flag is set, until gimmicks have finished popping (capped at 900 frames; see Field-Gimmicks). -
start_areajump/end_areajumprequest a map jump (GfReqCommand::reqMapjump) and wait until it is done;start_change/end_changeapplyStatusManager::changeFromBdat(chg*ID)(end_changefirst plays a 30-frame event fade unless skipping). -
exec_fadeoutrequests fade type 2 and a seamless volume fade, or a 30-frame skip fade when skipping.exec_grassis a "glass break" transition that runs until a given frame and fades in black on the end frame. -
checkWait3Dis true when play parameter 2 (the Blade id) andlinkIDare both 0;checkSyncBgmis false when the end fade-out is set ornextID == 0.
Not decompiled: SeqManager::exec::update (the event body loop, 0x710012b90c, 15,216 bytes), init (2,980), setupScene (6,068), startScene (8,764), end (2,212) and event::Manager::Manager (0x71001388c4, 9,728 bytes).
-
pluginRegist()(P/plugin_regist.cpp) registers the script command groups in order: builtin, thread, bdat, menu, aidata, wait, deb, sys, fld, party, ui, then about 20 event groups (Obj,Setup,Chara,Cam,Eff,Lgt,Post,Text,Sel,Status,Bgm,Se,Vol,Rand,Pay,Env,Mov,Map,Ui,Voice), then the battle AI group and the gimmick group. Only this registry and the camera, character, effect, object and text commands are defined in the source. - Each command is a factory that returns an
ITodo(doit,undo,redo, a command name). Camera: CamMotion, CamPos, CamMovePos, CamTar, CamMoveTar, CamFov, CamMoveFov, CamRotZ, CamMoveRotZ, CamNearfar, CamCut, CamFollowPos, CamFollowTar. Character: CharaWalkPos, CharaLinerPos, CharaTurnRot, CharaLinerRot, CharaTgt, CharaSetIdle, CharaAction, CharaMotion, CharaMotionABC, CharaHead, CharaFacial, CharaTalk, CharaWink, CharaMount, CharaFade. Effect: EffectPlay, EffectCast, EffectMount, EffectKill, EffectAnim, EffectMove, EffectTurn, EffectScale, EffectColor. Object and text: SetActive and PlayText. - Commands act on the "active object" set by
ScriptSetActive; objects form a tree (types inferred: tree, character, camera, effect, light), and most commands do nothing when the active object has the wrong type. -
Undo and scrubbing.
TodoManagerkeeps up to 128TodoItems, each stamped with the frame it ran at.addexecutes at once and discards the redo tail;undoredo(frame, ...)rewinds or replays to a frame. This is how event scrubbing (skip left/right,FrameManager::shiftLeft/Right) works. The list is cleared on scene start and page change. -
Script parameters.
Paramhas 10 variables,CmdParam11. Types: s32, f32, bool, string, user data; mixed int and float reads convert. -
Placement.
DataManagerkeeps a source and destination matrix pair per scene (setOffsetSrc/Des), so a scene authored once can be replayed at any world position and heading.PosAxisis the position reference of a script position (axes inferred: position, global position, "say" (the talker), character). -
Easing curves (
Curve::getValue,E/curve.cpp): 0 step (1.0 only at rate 1), 1 linear, 2 ease in-out Bézier (0,0,1,1), 3 ease-in (0,0,0.1,1), 4 ease-out (0,0.9,1,1), 5 weak ease-in (0,0,0.66,1), 6 weak ease-out (0,0.33,1,1).AnmBaseis a keyframe base with up to 16 keys.
-
FrameManagertracks the current frame, a max frame (default 1000) and the skippable total. There are 17 pause types (inferred roles: wait, skip, select, quest, common UI, field skill, shop, payoff, reward, random talk, the special Blade pair's UI, minigame, new-game wait, two "stop 3D" types and a game-layer pause);pause()also requests a game pause for some of them and forwards the state to the sound, voice, movie and CPU managers.shiftFrameseeks to a key frame (up to 512 key frames with a cut flag). -
SkipManagerhas flags for skip, skip volume and fast-skip enable.skip(true, frame)stops the movie and remembers an end frame (default 99999 when negative); it clears itself when the timeline reaches it. -
Text (
TextManager::play,E/text_manager.cpp): returns at once on fast skip or failure skip or when the text sheet is not loaded. Text comes from the event's message sheet (MstxtManager::getSeatID(label),getText(label)); a caption flag chooses caption or window. In "replace" mode the first two characters of the label are replaced by a name and the last character is set to1or2bymtRand(2). Labels ending inhpick a voice variant byStatusManager::getHomuriFlag(). A window text withlife >= 1locks the timeline atframe + life - 1until the text has finished writing; delay, life and "delayBack" drive show, hide and stop, and the talker also gets auto-action, auto-talk and talk commands. -
Random talk (
RandCalc,E/rand_calc.cpp): from theFLD_randomTalksheet it keeps rows whosetypematches, drops rows whosetalk0/talk1character is not in the scene, and picks one withmtRand(count); the timeline is paused with type 9 while it plays. -
Quest and mercenary hooks:
QuestManager::entry/setComp/disppause the frame manager with type 3 while the quest UI is active;MercenariesManager::entryablesets mission flag 1 andfinishcreatesSCOM_MISSION_COMPLETE.
-
Focal length to field of view (
CamUtil::toFov/toFocal): a 25.39 mm film width,fov = 2 * atan(25.39 / (2 * focal))in degrees.EVT_nearfaris read by id (name,near,far). -
CamManagerholds up to 8CamObjand 4CamInterfaces. ACamObjhas a field-camera mode, a script camera and a motion camera; defaults near 0.1, far 40000, FOV 40, roll 0. Each update pushes position, target, roll, FOV (clamped to a minimum of 5 degrees) and near/far into the interface, only while the stream delta is above 0 and not in free camera. Camera motions are.evafiles. -
Depth of field (
DofManager, sheetEVT_dof): columnsdist,range,pixel,lens,strength,blend,pixelLv,hlv,name; the simple mode readsfoMininstead ofdistandrange. Defaults with no DOF: axis 1, range 5, focus minimum 0.1, pixel 5, lens 0.6, strength 4, blend 1. Axis 1 is the camera, axis 2 the current talker, axis 3 and above are characteraxis - 3; for a character the distance is camera-to-eye distance times the cosine against the camera direction. -
rcha(animation tracks baked into resources):RchaNodehas 48 tracks whose names are hashed with 32-bit FNV-1 (offset basis0x811c9dc5, prime0x1000193, up to 128 characters).RchaCamhas 30 slots: translation, rotation and order, near, far, FOV, depth of field (enable, distance, range, pixel, lens, strength, blend, pixel level, hlv), motion blur (enable, strength, sub), shadow-map visibility, clock (enable and hour), weather (enable, type), fade, camera-light stop and near/far type. Defaults when a track is missing: FOV 30, near 0.1, far 80000, DOF distance 20, range 40, pixel 5, lens 0.6, strength 4, blend 1, blur strength 0.5, sub 0.1; the hour is clamped to 0 to 23.999998 and "enable" tracks mean "value above 0.9".CRchaEx(29 slots) carries per-character tracks (dummy, dynamics blend, weapon display and transform, mount, battle, foot effects, action id, face preset, eye type, object transform, aim target).
-
CharaObjembeds about 25 command objects and runs them on two 8-slotCmdQueues plus a 5-slot fade queue, with IK, dynamics, target, lens, weight, wink, effect and part updaters. Character types (inferred): 1 driver, 2 Blade, 3 NPC, 5 enemy. -
Actions (sheet
EVT_acttype; columnsname,cmd0..2,stat0..2,statI): a play runscmd0, starts statestat0, loopsstat1, and finishes whenstat2reachesstatI; life 0 or below loops forever; blend-in is disabled while skipping. Action row 22 (ACT_BATTLE) calls the weapon battle command for model types 0, 1, 2 and 5. -
Idle, head, brow, eye, lip, wink have their own sheets (
EVT_idletype,EVT_headtypewithstat,name,blend,weight;EVT_browtype,EVT_eyetypewithdisableWink,EVT_liptypewithdisableTalkLip,EVT_winktype). Facial animation is built from weighted animation layers byCharaWeightPlayer(up to 12 simultaneous items). The facial asset of a character is found throughCHR_Dr.EventAsset(drivers),CHR_Bl.EventAsset(Blades) orRSC_NpcList.EventAsset(NPCs), whose value indexesEVT_assetList(facialSeat,lensID).EVT_lensgives eye-lens limits (thMin/thMax/tvMin/tvMaxscaled by 0.001,rhMin/rhMax/rvMin/rvMaxin degrees). -
Blinking (
CharaWinkPlayer): idle blink everymtRand(60) + 90frames (90 to 149); eyes stay closed 7 frames with a 4-frame blend. -
Looking at a target (sheet
EVT_aimmottype, 6 aim motions: up, down (non-spine), up, down (spine), left, right):CharaTarUtil::calcWeightturns the direction into yaw and pitch relative to the character's facing, wraps to ±π, clamps pitch to ±30° and yaw to ±90°, and normalises both to -1..1;CharaTarPlayerMot::updateadds those as weights. -
Walking (
CharaWalkCalculator): accelerate, cruise, decelerate. Blend frames: walk 10, run 20. Top speed per frame: walk 0.056, run 0.259. Acceleration length at framefistop * f / blend. -
Scheduler: hand-offs between field and event for NPCs and party characters: field to event, event to idle, event to field (
Scheduler::setup/play); NPCs additionally get turn, return, and (when holding an item) fade and item steps.
-
GfGameEventowns the event manager, 128 event models (FixedList<GfEvtModel*, 128>), event BGM and SE. Each frame:manager->update(); tail(); render();then the objects and BGM. -
Notifications use
GfEvent(up to 32 listeners):GEV1 to 7 for the area jump steps, 8 to 10 event end wait, event end, event play end, 11 and 12 sequence start and end, 13 start frame, 14 and 15 player control free and lock. On code 9 the game enters the "play" state and takes control from the player; on 10 it sets the played flag, gives control back and runsGfPlayFactory::createEventAfterScript; on 11 it enters the "sequence" state; on 12 it resets the fade-in time (wait 0 s, fade 0.5 s by default) and clears temporary weather.gf::GF_STATEhas 25 game states (for example 4 talk, 7 wait event, 14 map gimmick, 20 event, 22 chain attack, 23 arts movie). -
Hiding. The event can hide world content by class: 26 display classes (
EVTDISP_*, map 1, PC 3, Blade 4, enemy 5, NPC 6, mob 7, field object 9, PC weapon 10, enemy weapon 12, collection 16, salvage 17, precious 18, treasure box 19, jump 22, warp 23, damage effect 24, damage SE 25). Classes 16 and above go to gimmick types (GfGameUtil::setDispByGmkType); lower classes are applied per object with an event-hide id list of up to 1024 ids (type << 16 | bdat id). Individual gimmicks can be hidden by BDAT id and are restored when the scene ends (HideManager).OutsiderManagerhides non-event actors and can hide a spherical area (defineFld). - Gimmicks start events:
GmkEvent::beginEventcallsGfPlayFactory::createOneEventForGimmick;GmkKizunaTalk::onPlayerAccessedcallscreateOneEvent;GmkMapJumpcallscreateMapjump(see Field-Gimmicks).
Event manager core: Manager::Manager, SeqManager::exec::update, startScene, setupScene, init, end, start_form::update. Timing: FrameManager::update (0x7100125b40, 2,468), shiftLeft, shiftRight (2,876), TodoManager::insert. Camera: CamEvaPlayer::update (2,584), getCamLook_roll (2,980), CamFree::getViewMatrix, ManiManager::updateManipulate (0x71001066d4, 9,124). Characters: CharaObj::CharaObj (2,368), update, initModel, initModelStream (4,608), CharaPlayEva::update, CharaWalkPos::update, CharaWalkCalculator::calcPos, CharaSetTar::update, the talk, wink and facial play functions. Objects, resources and status: StatusManager::change (0x71000f7294, 7,344), SelectManager::play, BgmManager::play/update/clear, FormManager::replace, MdlstmData::getReplaceInfo.