V-Gears 0
Free Final Fantasy VII engine.
FieldEngine.h
Go to the documentation of this file.
1/*
2 * V-Gears
3 * Copyright (C) 2022 V-Gears Team
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#pragma once
20
21#include <string>
22#include <vector>
23
27
31class FieldEngine : public Engine{
32
33 public:
34
41 class Entity{
42 public:
43
49 Entity() = default;
50
59 Entity(const std::string& name, size_t index);
60
66 std::string GetName() const;
67
76 size_t GetIndex() const;
77
88 std::string FunctionByIndex(size_t index) const;
89
99 void AddFunction(const std::string& name, size_t index);
100
111 void MarkAsLine(bool line, std::vector<float> point_a, std::vector<float> point_b);
112
122 bool IsLine();
123
131 std::vector<float> GetLinePointA();
132
140 std::vector<float> GetLinePointB();
141
142
143
144 private:
145
149 std::string name_;
150
154 size_t index_;
155
159 std::map<size_t, std::string> functions_;
160
165
171 std::vector<float> point_a_;
172
178 std::vector<float> point_b_;
179 };
180
187 FieldEngine(FieldScriptFormatter& formatter, std::string script_name);
188
194 FieldEngine(const FieldEngine& engine) = delete;
195
201 FieldEngine& operator = (const FieldEngine& engine) = delete;
202
210 virtual std::unique_ptr<Disassembler> GetDisassembler(
211 InstVec &insts, const std::vector<unsigned char>& raw_script_data
212 ) override;
213
220 virtual std::unique_ptr<Disassembler> GetDisassembler(InstVec &insts) override;
221
229 virtual std::unique_ptr<CodeGenerator> GetCodeGenerator(
230 const InstVec& insts, std::ostream &output
231 ) override;
232
241 virtual void PostCFG(InstVec &insts, Graph graph) override;
242
248 virtual bool UsePureGrouping() const override;
249
255 std::map<std::string, int> GetEntities() const;
256
262 std::vector<FieldDecompiler::FieldEntity> GetEntityList() const;
263
269 std::vector<FieldDecompiler::Line> GetLineList() const;
270
276 std::map<size_t, Entity> GetEntityIndexMap() const{return entity_index_map_;}
277
287 const std::string& entity_name, size_t entity_index,
288 const std::string& func_name, size_t func_index
289 );
290
302 void MarkEntityAsLine(
303 size_t entity_index, bool line, std::vector<float> point_a, std::vector<float> point_b
304 );
305
313 bool EntityIsLine(size_t entity_index);
314
322 const Entity& EntityByIndex(size_t index) const;
323
329 float GetScaleFactor() const;
330
336 const std::string& GetScriptName() const;
337
338 private:
339
350
362 void RemoveTrailingInfiniteLoops(InstVec& insts, Graph graph);
363
372 void MarkInfiniteLoopGroups(InstVec& insts, Graph graph);
373
378
382 std::map<size_t, Entity> entity_index_map_;
383
388
392 std::string script_name_;
393};
boost::adjacency_list< boost::setS, boost::listS, boost::bidirectionalS, GraphProperty, EdgeProperty > Graph
Definition: Graph.h:169
std::vector< InstPtr > InstVec
Type representing a vector of InstPtrs.
Definition: Instruction.h:382
Base class for engines.
Definition: Engine.h:34
Any entity in a field.
Definition: Entity.h:101
Represents an entity.
Definition: FieldEngine.h:41
size_t index_
Entity index.
Definition: FieldEngine.h:154
void AddFunction(const std::string &name, size_t index)
Adds a function to the engine.
Definition: FieldEngine.cpp:68
std::string FunctionByIndex(size_t index) const
Retrieves a function.
Definition: FieldEngine.cpp:62
std::string GetName() const
Retrieves the entity name.
Definition: FieldEngine.cpp:58
std::vector< float > point_a_
The first point of a line entity.
Definition: FieldEngine.h:171
size_t GetIndex() const
Retrieves the entity index.
Definition: FieldEngine.cpp:60
bool is_line_
Indicates if the entity is a line.
Definition: FieldEngine.h:164
std::map< size_t, std::string > functions_
Entity function (script) list.
Definition: FieldEngine.h:159
bool IsLine()
Checks if the entity is a line.
Definition: FieldEngine.cpp:97
std::vector< float > point_b_
The second point of a line entity.
Definition: FieldEngine.h:178
std::vector< float > GetLinePointB()
Retrieves the second point of the line entity.
Definition: FieldEngine.cpp:101
Entity()=default
Entity constructor.
std::vector< float > GetLinePointA()
Retrieves the first point of the line entity.
Definition: FieldEngine.cpp:99
void MarkAsLine(bool line, std::vector< float > point_a, std::vector< float > point_b)
Marks the entity as a line.
Definition: FieldEngine.cpp:72
std::string name_
Entity name.
Definition: FieldEngine.h:149
Represents the FF7 Field engine.
Definition: FieldEngine.h:31
FieldScriptFormatter & formatter_
The script formatter.
Definition: FieldEngine.h:377
float scale_factor_
The map scale factor.
Definition: FieldEngine.h:387
const Entity & EntityByIndex(size_t index) const
Retrieves an entity.
Definition: FieldEngine.cpp:230
std::vector< FieldDecompiler::FieldEntity > GetEntityList() const
Retrieves all non-line entities in the map.
Definition: FieldEngine.cpp:163
void AddEntityFunction(const std::string &entity_name, size_t entity_index, const std::string &func_name, size_t func_index)
Adds a function to an entity.
Definition: FieldEngine.cpp:202
float GetScaleFactor() const
Retrieves the scale factor for the map.
Definition: FieldEngine.cpp:236
std::map< size_t, Entity > GetEntityIndexMap() const
Retrieves all entities in the map.
Definition: FieldEngine.h:276
FieldEngine & operator=(const FieldEngine &engine)=delete
Copy constructor, disabled.
void RemoveTrailingInfiniteLoops(InstVec &insts, Graph graph)
Removes trailing infinite loops.
Definition: FieldEngine.cpp:261
void MarkEntityAsLine(size_t entity_index, bool line, std::vector< float > point_a, std::vector< float > point_b)
Marks an entity as a line.
Definition: FieldEngine.cpp:215
virtual void PostCFG(InstVec &insts, Graph graph) override
Post-processing actions to apply to the scripts.
Definition: FieldEngine.cpp:130
std::map< size_t, Entity > entity_index_map_
The entity index map for the field.
Definition: FieldEngine.h:382
std::vector< FieldDecompiler::Line > GetLineList() const
Retrieves all line entities in the map.
Definition: FieldEngine.cpp:188
virtual bool UsePureGrouping() const override
Indicates if instructions are purely grouped.
Definition: FieldEngine.cpp:144
FieldEngine(const FieldEngine &engine)=delete
Copy constructor, disabled.
std::string script_name_
The script name.
Definition: FieldEngine.h:392
void RemoveExtraneousReturnStatements(InstVec &insts, Graph graph)
Removes extraneous return statements.
Definition: FieldEngine.cpp:240
bool EntityIsLine(size_t entity_index)
Checks if an entity has been marked as a line.
Definition: FieldEngine.cpp:224
std::map< std::string, int > GetEntities() const
Retrieves all entities in the map.
Definition: FieldEngine.cpp:146
const std::string & GetScriptName() const
Retrieves the script name.
Definition: FieldEngine.cpp:238
virtual std::unique_ptr< CodeGenerator > GetCodeGenerator(const InstVec &insts, std::ostream &output) override
Retrieves the code generator.
Definition: FieldEngine.cpp:121
virtual std::unique_ptr< Disassembler > GetDisassembler(InstVec &insts, const std::vector< unsigned char > &raw_script_data) override
Retrieves the disasembler.
Definition: FieldEngine.cpp:107
void MarkInfiniteLoopGroups(InstVec &insts, Graph graph)
Tries to detect scripts with trailing infinite loops.
Definition: FieldEngine.cpp:282
FieldEngine(FieldScriptFormatter &formatter, std::string script_name)
Constructor.
Definition: FieldEngine.cpp:103
Formatter for field scripts.
Definition: FieldScriptFormatter.h:26
DummyFormatter formatter
Definition: ff7_field_disasm_all_opcodes_by_category_test.cpp:1966