OpenUT99-Plus
Unreal Engine 1, rebuilt from scratch
Loading...
Searching...
No Matches
world.h
Go to the documentation of this file.
1// Actor world: a map's actors as live VM objects, play start, ticking, timers, Actor natives (ADR 0006).
2// Spec: docs/formats/script.md (execution); behaviour marked unverified there until compared with the original.
3#pragma once
4#include <functional>
5#include <map>
6#include <memory>
7#include <set>
8#include <string>
9#include <vector>
10
11#include "collision.h"
12#include "level.h"
13#include "mesh.h"
14#include "packages.h"
15#include "vm.h"
16
17namespace ut {
18
19// What the keys and mouse say this tick, in the retail default bindings' units (User.ini aliases).
21 float forward = 0; // aBaseY: +300 forward, -300 back
22 float strafe = 0; // aStrafe: +300 right, -300 left
23 float turn = 0, look = 0; // aBaseX (+-150) / aLookUp (+-100): keyboard turning
24 float mouse_x = 0, mouse_y = 0; // aMouseX / aMouseY: pixels this tick x 6 (Axis aMouseX Speed=6.0)
25 bool fire = false, alt_fire = false, duck = false; // bFire / bAltFire / bDuck while held
26 bool jump = false; // pressed this tick: exec Jump
27 int weapon = 0; // 1-10 pressed this tick: exec SwitchWeapon(N); 0 none
28 std::string command; // an exec function without arguments to call this tick (e.g. "Suicide")
29};
30// A fixed 20 s of play for headless checks: fire (starts the match), forward, strafe right, hold fire, Suicide at
31// 10 s, fire (respawn), forward. t: match time at the start of the tick.
32PlayerInput scripted_input(float t, float dt);
33
34class World {
35public:
36 World(Vm& vm, PackageSet& packages); // registers the Actor natives on vm
37 // Every actor of the map's Level becomes a live instance; then the game class (LevelInfo.DefaultGameType, else
38 // default_game "Package.Class") is spawned as Level.Game (InitGame and play events come in begin_play).
39 void load(const std::string& map, const std::string& default_game = "");
40 // InitGame(options: the URL's "?Key=Value" part, e.g. ?mutator=Pkg.Class), then PreBeginPlay, BeginPlay,
41 // PostBeginPlay, SetInitialState phase by phase.
42 void begin_play(const std::string& options = "");
43 void tick(float dt); // Level.TimeSeconds, Tick events, timers, state code
44 Obj* spawn(Obj* cls, Obj* spawner, Obj* owner, const std::string* tag, const Value* loc, const Value* rot);
45
46 std::vector<Obj*> actors;
47 Obj* level_info = nullptr;
48 Obj* game = nullptr;
49 float time = 0;
50 std::map<std::string, int> errors; // script errors (without the function name) -> count; the world goes on
51 bool destroyed(Obj* o) const { return deleted_.count(o) > 0; } // Destroy()ed: still listed, no longer in play
52 const Model* model() const { return has_model_ ? &model_ : nullptr; }
53 void set_model(Model m) { model_ = std::move(m), has_model_ = true; } // load() does it; for tests
54 // ZoneInfo of the BSP leaf holding p (the LevelInfo for zone 0); also its zone number and leaf if asked.
55 Obj* zone_at(Vec3 p, int* number, int* leaf);
56 // Region (Zone, iLeaf, ZoneNumber) from Location, ZoneChange when it changes; pawns also FootRegion / HeadRegion.
57 void update_region(Obj* o);
58 void set_region(Obj* o, const char* var, Vec3 at, const char* event);
59
60 // The local player (world_player.cpp). login: Level.Game's Login + PostLogin, after begin_play; options as in a
61 // URL ("?Name=Player?Class=Botpack.TMale1"). Returns the pawn, or nullptr (the reason in errors["login: ..."]).
62 Obj* login(const std::string& options, const std::string& player_class);
63 Obj* player = nullptr; // the logged-in pawn; nullptr when none or destroyed
64 PlayerInput input; // read by tick(); the one-tick fields (jump, weapon, mouse) are cleared after
65 // The player's PlayerCalcView: camera location and rotation (Unreal units); false without a player.
66 bool player_view(Vec3* location, int32_t rotation[3]);
67
68private:
69 void guarded(Obj* o, const std::string& event, std::vector<Value> args = {});
70 Obj* find_class(const std::string& pkg_dot_class); // "Package.Class" -> class object, nullptr if none
71 void player_tick(float dt); // input variables, exec commands, PlayerInput, PlayerTick
72
73 void destroy(Obj* o);
74 void physics(Obj* o, float dt);
75 // Sweeps the actor's collision box (if it collides with the world); *what = what it hit (LevelInfo = the BSP).
76 Hit move(Obj* o, Vec3 delta, Obj** what = nullptr);
77 // The level BSP and every blocking mover brush; *what = the LevelInfo, a mover or nullptr.
78 Hit trace_world(Obj* self, Vec3 a, Vec3 b, Vec3 extent, Obj** what = nullptr);
79 // The first actor blocking o's move a-b before h->time; then updates *h (hit, time, normal).
80 Obj* blocking_actor(Obj* o, Vec3 a, Vec3 b, Hit* h);
81 void bump(Obj* o, Obj* other); // Bump on both
82 Hit trace_brush(Obj* mover, Vec3 a, Vec3 b, Vec3 extent); // one mover alone (no hit if it does not block)
83 void move_brush(Obj* o, float dt); // PHYS_MovingBrush: InterpolateTo's keyframe glide, carries what stands on it
84 void set_base(Obj* o, Obj* base); // Base, StandingCount, Detach / Attach / BaseChange
85 struct Brush {
86 Model model; // the mover's BSP in its local space
87 float radius; // of its points around the local origin, for a quick rejection
88 };
89 std::map<Obj*, Brush> movers_;
90 void add_mover(Obj* o); // reads its Brush model (throws on bad data)
91 const LodMesh::AnimSeq* seq(Obj* o, const std::string& name); // sequence of the actor's mesh
92 // AI (world_ai.cpp): path network from the map's reach specs, routes, latent moves.
93 void register_ai();
94 bool reachable(Obj* pawn, Vec3 dest);
95 // Route from the pawn to the nearest goal: fills Pawn.RouteCache, returns the first step (nullptr: no route).
96 // weight(nav, distance) > 0 marks a goal; the best weight wins.
97 Obj* route(Obj* pawn, const std::function<float(Obj*, float)>& weight, float* best);
98 void walk(Obj* o, float dt);
99 void sight(Obj* o, float dt); // SeePlayer / EnemyNotVisible
100 // Closest actor hit by the segment a-b before *t_hit (fraction); updates *t_hit and *normal.
101 Obj* trace_actors(Obj* self, Vec3 a, Vec3 b, float* t_hit, Vec3* normal, const std::set<Obj*>* skip = nullptr);
102 std::set<std::pair<Obj*, Obj*>> seen_; // (viewer, seen) last time it looked
103 struct Edge {
104 Obj* to;
105 float distance;
106 int radius, height;
107 };
108 std::map<Obj*, std::vector<Edge>> paths_;
109 std::map<Obj*, float> speed_; // MoveTo speed factor of a pawn
110 void touches(Obj* o); // Touch / UnTouch of a moving actor against the actors it overlaps
111 std::set<std::pair<Obj*, Obj*>> touching_; // both orders
112 std::vector<Obj*> navs_;
113 bool anim_done(Obj* o);
114 void animate(Obj* o, float dt); // advances AnimFrame, AnimEnd when a sequence (or a loop round) ends
115 std::map<const Obj*, std::unique_ptr<LodMesh>> meshes_; // by mesh object; nullptr if not a readable LodMesh
116 std::map<Obj*, float> tweens_; // TweenAnim time left
117
118 const Package* map_ = nullptr;
119 Model model_;
120 bool has_model_ = false;
121
122 Vm& vm_;
123 PackageSet& packages_;
124 std::set<Obj*> deleted_;
125 bool begun_ = false; // false while the map's actors load: they get their play events in begin_play
126 size_t map_actors_ = 0; // the actors loaded from the map, first in `actors`
127};
128
129} // namespace ut
Definition packages.h:16
Definition vm.h:83
float time
Definition world.h:49
Obj * spawn(Obj *cls, Obj *spawner, Obj *owner, const std::string *tag, const Value *loc, const Value *rot)
Definition world.cpp:382
void tick(float dt)
Definition world.cpp:752
Obj * login(const std::string &options, const std::string &player_class)
Definition world_player.cpp:34
std::vector< Obj * > actors
Definition world.h:46
void set_model(Model m)
Definition world.h:53
Obj * player
Definition world.h:63
void set_region(Obj *o, const char *var, Vec3 at, const char *event)
Definition world.cpp:479
bool player_view(Vec3 *location, int32_t rotation[3])
Definition world_player.cpp:107
void update_region(Obj *o)
Definition world.cpp:508
PlayerInput input
Definition world.h:64
World(Vm &vm, PackageSet &packages)
Definition world.cpp:27
Obj * game
Definition world.h:48
void load(const std::string &map, const std::string &default_game="")
Definition world.cpp:305
bool destroyed(Obj *o) const
Definition world.h:51
Obj * level_info
Definition world.h:47
const Model * model() const
Definition world.h:52
std::map< std::string, int > errors
Definition world.h:50
Obj * zone_at(Vec3 p, int *number, int *leaf)
Definition world.cpp:464
void begin_play(const std::string &options="")
Definition world.cpp:367
Definition collision.cpp:7
PlayerInput scripted_input(float t, float dt)
Definition world_player.cpp:24
Definition collision.h:7
Definition level.h:38
Definition vm.h:35
Definition world.h:20
float mouse_x
Definition world.h:24
bool alt_fire
Definition world.h:25
std::string command
Definition world.h:28
float turn
Definition world.h:23
bool duck
Definition world.h:25
float look
Definition world.h:23
float forward
Definition world.h:21
float strafe
Definition world.h:22
float mouse_y
Definition world.h:24
int weapon
Definition world.h:27
bool jump
Definition world.h:26
bool fire
Definition world.h:25
Definition vm.h:21
Definition upkg.h:66