V-Gears 0
Free Final Fantasy VII engine.
EntityManager.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022 The V-Gears Team
3 *
4 * This file is part of V-Gears
5 *
6 * V-Gears is free software: you can redistribute it and/or modify it under
7 * terms of the GNU General Public License as published by the Free Software
8 * Foundation, version 3.0 (GPLv3) of the License.
9 *
10 * V-Gears 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
16#pragma once
17
18#include <OgreSingleton.h>
19#include "Background2D.h"
20#include "Entity.h"
21#include "EntityPoint.h"
22#include "EntityTrigger.h"
23#include "Event.h"
24#include "Manager.h"
25#include "Walkmesh.h"
26
30class EntityManager : public Manager, public Ogre::Singleton<EntityManager>{
31
32 public:
33
38
42 virtual ~EntityManager();
43
49 void Input(const VGears::Event& event) override;
50
56 void UpdateDebug() override;
57
61 void OnResize() override;
62
68 void ClearField() override;
69
75 void ClearBattle() override;
76
82 void ClearWorld() override;
83
90
97
109 void AddEntity(
110 const Ogre::String& name, const Ogre::String& file_name,
111 const Ogre::Vector3& position, const Ogre::Degree& direction, int index
112 );
113
127 void AddEntity(
128 const Ogre::String& name, const Ogre::String& file_name,
129 const Ogre::Vector3& position, const Ogre::Degree& rotation,
130 const Ogre::Vector3& scale, const Ogre::Quaternion& root_orientation, const int index
131 );
132
146 void ScriptAddEntity(
147 const char* name, const char* file_name,
148 const float x, const float y, const float z, const float direction, int index
149 );
150
162 void AddEntityTrigger(
163 const Ogre::String& name, const Ogre::Vector3& point1,
164 const Ogre::Vector3& point2, const bool enabled
165 );
166
176 void AddEntityPoint(
177 const Ogre::String& name, const Ogre::Vector3& position, const float rotation
178 );
179
185 void AddEntityScript(const Ogre::String& name);
186
192 void ScriptAddEntityScript(const char* name);
193
202 Entity* GetEntity(const Ogre::String& name) const;
203
212 Entity* GetEntityFromIndex(const int id) const;
213
222 Entity* GetEntityFromCharacterId(const int id) const;
223
232 Entity* ScriptGetEntity(const char* name) const;
233
241 EntityPoint* ScriptGetEntityPoint(const char* name) const;
242
252 void ScriptSetPlayerEntity(const char* name);
253
261
268
276 void ScriptPlayerLock(const bool lock);
277
286 void SetPlayerMoveRotation(const Ogre::Radian rotation);
287
293 bool GetRandomEncounters();
294
300 void SetRandomEncounters(bool active);
301
307 float GetEncounterRate();
308
314 void SetEncounterRate(float rate);
315
322 bool IsKeyOn(unsigned int key_code);
323
330 bool IsKeyOff(unsigned int key_code);
331
340 void SetEntityToCharacter(const char* entity_name, unsigned int char_id);
341
347 Entity* GetBackground3D() const;
348
355 void SetBackground3D(const Ogre::String& name, const Ogre::String& file_name);
356
357 private:
358
368 static float PointElevation(
369 const Ogre::Vector2& point,
370 const Ogre::Vector3& a, const Ogre::Vector3& b, const Ogre::Vector3& c
371 );
372
383 static float SideOfVector(
384 const Ogre::Vector2& point, const Ogre::Vector2& p1, const Ogre::Vector2& p2
385 );
386
399 static float SquareDistanceToLine(
400 const Ogre::Vector3& point, const Ogre::Vector3& point_a, const Ogre::Vector3& point_b,
401 Ogre::Vector3& proj
402 );
403
411 static Ogre::Degree GetDirectionToPoint(
412 const Ogre::Vector3& current_point, const Ogre::Vector3& direction_point
413 );
414
418 static const float SCENE_SCALE;
419
423 static const unsigned int BATTLE_BACKGROUND_ID;
424
428 static const unsigned int WORLD_MAP_BACKGROUND_ID;
429
433 void UpdateField() override;
434
438 void UpdateBattle() override;
439
443 void UpdateWorld() override;
444
457 const Ogre::String& name, const Ogre::String& file_name,
458 const Ogre::Vector3& position, const Ogre::Degree& rotation,
459 const Ogre::Vector3& scale, const Ogre::Quaternion& root_orientation, const int index
460 );
461
475 void AddBattleEntity(
476 const Ogre::String& name, const Ogre::String& file_name,
477 const Ogre::Vector3& position, const Ogre::Degree& orientation,
478 const Ogre::Vector3& scale, const Ogre::Quaternion& root_orientation, const int index
479 );
480
493 bool SetEntityOnWalkmesh(Entity* entity);
494
505 bool PerformWalkmeshMove(Entity* entity, const float speed);
506
517 Entity* entity, Ogre::Vector3& position, const Ogre::Vector2& move_vector
518 );
519
528 bool CheckSolidCollisions(Entity* entity, Ogre::Vector3& position);
529
536 void SetEntityDirectionByVector(Entity* entity, const Ogre::Vector2& vector);
537
549 void CheckTriggers(Entity* entity, const Ogre::Vector3& position);
550
559 void CheckEntityInteract();
560
566 void SetNextOffsetStep(Entity* entity);
567
573 void SetNextTurnStep(Entity* entity);
574
582 void SetNextLinearStep(Entity* entity);
583
591 void SetNextJumpStep(Entity* entity);
592
596 void SetNextScrollStep();
597
602
607
612
616 std::vector<Entity*> entity_;
617
621 std::vector<Entity*> battle_entity_;
622
627
632
638 Ogre::Vector3 player_move_;
639
646
651
658
662 std::vector<EntityTrigger*> entity_triggers_;
663
667 std::vector<EntityPoint*> entity_points_;
668
672 std::vector<Ogre::String> entity_scripts_;
673
677 Ogre::SceneNode* scene_node_;
678
682 Ogre::Entity* grid_;
683
687 Ogre::Entity* axis_;
688
693
698};
float * position
Used to keep track of the skeleton and it's bones positions.
Definition: DrawSkeleton.cpp:33
uint16 a
Alpha component.
Definition: TxzFileSerializer.h:19
uint16 b
Blue component.
Definition: TxzFileSerializer.h:14
A field background.
Definition: Background2D.h:29
The entity manager.
Definition: EntityManager.h:30
Walkmesh walkmesh_
The map walkmesh.
Definition: EntityManager.h:601
bool PerformWalkmeshMove(Entity *entity, const float speed)
Moves an entity in the walkmesh.
Definition: EntityManager.cpp:751
Ogre::Entity * grid_
Definition: EntityManager.h:682
Ogre::String entity_table_name_
The entity table name.
Definition: EntityManager.h:611
void ClearBattle() override
Clears all battle information in the entity manager.
Definition: EntityManager.cpp:449
bool random_encounters_
Indicates if random encounters happen in the map.
Definition: EntityManager.h:692
bool CheckSolidCollisions(Entity *entity, Ogre::Vector3 &position)
Checks for collisions of the entity with other entities.
Definition: EntityManager.cpp:1047
Background2D background_2d_
The map background.
Definition: EntityManager.h:606
void ScriptAddEntity(const char *name, const char *file_name, const float x, const float y, const float z, const float direction, int index)
Adds an entity to the manager.
Definition: EntityManager.cpp:507
float encounter_rate_
The encounter rate of the map.
Definition: EntityManager.h:697
bool IsKeyOff(unsigned int key_code)
Checks if a key is not being pressed.
Definition: EntityManager.cpp:674
bool GetRandomEncounters()
Checks if random battle encounters are active in the field.
Definition: EntityManager.cpp:646
bool WalkmeshBorderCross(Entity *entity, Ogre::Vector3 &position, const Ogre::Vector2 &move_vector)
Checks if the entity is crossing a walkmesh triangle border.
Definition: EntityManager.cpp:1005
void UpdateWorld() override
Updates the world map entities in the manager.
Definition: EntityManager.cpp:307
std::vector< EntityTrigger * > entity_triggers_
List of triggers.
Definition: EntityManager.h:662
Ogre::Radian player_move_rotation_
The playable entity current movement turn indicator.
Definition: EntityManager.h:645
void ClearField() override
Clears all field information in the entity manager.
Definition: EntityManager.cpp:422
static const unsigned int WORLD_MAP_BACKGROUND_ID
Entity ID for world map background entity.
Definition: EntityManager.h:428
void ScriptAddEntityScript(const char *name)
Adds an entity script to the manager.
Definition: EntityManager.cpp:546
Ogre::Vector3 player_move_
The playable entity current movement indicator.
Definition: EntityManager.h:638
void CheckTriggers(Entity *entity, const Ogre::Vector3 &position)
Checks for entity triggers near a entity.
Definition: EntityManager.cpp:1072
bool player_run_
Indicates if the playable is being moved by running.
Definition: EntityManager.h:657
Entity * player_entity_
The player controlled entity.
Definition: EntityManager.h:631
void AddEntity(const Ogre::String &name, const Ogre::String &file_name, const Ogre::Vector3 &position, const Ogre::Degree &direction, int index)
Adds an entity to the manager.
Definition: EntityManager.cpp:484
float GetEncounterRate()
Get the encounter rate for the field.
Definition: EntityManager.cpp:650
void SetRandomEncounters(bool active)
Enables or disables random encounters in the field.
Definition: EntityManager.cpp:648
void ScriptSetPlayerEntity(const char *name)
Sets the playable entity.
Definition: EntityManager.cpp:597
EntityPoint * ScriptGetEntityPoint(const char *name) const
Retrieves an entity point by name.
Definition: EntityManager.cpp:591
Ogre::SceneNode * scene_node_
The scene node.
Definition: EntityManager.h:677
void AddBattleEntity(const Ogre::String &name, const Ogre::String &file_name, const Ogre::Vector3 &position, const Ogre::Degree &orientation, const Ogre::Vector3 &scale, const Ogre::Quaternion &root_orientation, const int index)
Adds a battle entity to the manager.
Definition: EntityManager.cpp:331
std::vector< Entity * > battle_entity_
The list of battle entities.
Definition: EntityManager.h:621
void AddEntityScript(const Ogre::String &name)
Adds an entity script to the manager.
Definition: EntityManager.cpp:540
void SetNextTurnStep(Entity *entity)
Calculates the next turn step for an entity.
Definition: EntityManager.cpp:1278
virtual ~EntityManager()
Destructor.
Definition: EntityManager.cpp:126
static Ogre::Degree GetDirectionToPoint(const Ogre::Vector3 &current_point, const Ogre::Vector3 &direction_point)
Calculates the direction degree between to points.
Definition: EntityManager.cpp:92
Entity * background_3d_
A 3D background.
Definition: EntityManager.h:626
EntityManager()
Constructor.
Definition: EntityManager.cpp:103
Entity * ScriptGetEntity(const char *name) const
Retrieves an entity by name.
Definition: EntityManager.cpp:587
Entity * GetBackground3D() const
Retrieves the entity associated to the 3D background.
Definition: EntityManager.cpp:375
void SetBackground3D(const Ogre::String &name, const Ogre::String &file_name)
Sets the 3D model for the background.
Definition: EntityManager.cpp:383
void CheckEntityInteract()
Checks if an entity can be interacted.
Definition: EntityManager.cpp:1209
std::vector< Ogre::String > entity_scripts_
List of scripts.
Definition: EntityManager.h:672
bool player_lock_
Indicates if player control is locked.
Definition: EntityManager.h:650
void AddFieldOrWorldMapEntity(const Ogre::String &name, const Ogre::String &file_name, const Ogre::Vector3 &position, const Ogre::Degree &rotation, const Ogre::Vector3 &scale, const Ogre::Quaternion &root_orientation, const int index)
Adds a field entity to the manager.
Definition: EntityManager.cpp:311
bool SetEntityOnWalkmesh(Entity *entity)
Attaches an entity to the walkmesh.
Definition: EntityManager.cpp:699
Entity * ScriptGetPlayerEntity() const
Retrieves the playable entity.
Definition: EntityManager.cpp:613
void ScriptPlayerLock(const bool lock)
Locks or unlocks player control of the playable entity.
Definition: EntityManager.cpp:629
static const float SCENE_SCALE
Scale factor for battle background models.
Definition: EntityManager.h:418
Walkmesh * GetWalkmesh()
Retrieves the walkmesh.
Definition: EntityManager.cpp:480
std::vector< EntityPoint * > entity_points_
List of points.
Definition: EntityManager.h:667
Ogre::Entity * axis_
Definition: EntityManager.h:687
void AddEntityTrigger(const Ogre::String &name, const Ogre::Vector3 &point1, const Ogre::Vector3 &point2, const bool enabled)
Adds an entity trigger to the manager.
Definition: EntityManager.cpp:512
static float PointElevation(const Ogre::Vector2 &point, const Ogre::Vector3 &a, const Ogre::Vector3 &b, const Ogre::Vector3 &c)
Calculates the point elevation over a plane.
Definition: EntityManager.cpp:46
void SetEntityToCharacter(const char *entity_name, unsigned int char_id)
Assigns a character to an entity.
Definition: EntityManager.cpp:676
Entity * GetEntity(const Ogre::String &name) const
Retrieves an entity by name.
Definition: EntityManager.cpp:548
void SetPlayerMoveRotation(const Ogre::Radian rotation)
Sets the baseline rotation for the player controlled entity.
Definition: EntityManager.cpp:638
static const unsigned int BATTLE_BACKGROUND_ID
Entity ID for battle background entity.
Definition: EntityManager.h:423
void UpdateField() override
Updates the field entities in the manager.
Definition: EntityManager.cpp:176
void Input(const VGears::Event &event) override
Handles an input event.
Definition: EntityManager.cpp:136
void SetEntityDirectionByVector(Entity *entity, const Ogre::Vector2 &vector)
Sets an entity direction.
void SetEncounterRate(float rate)
Sets the battle encounter rate.
Definition: EntityManager.cpp:652
bool IsKeyOn(unsigned int key_code)
Checks if a key is being pressed.
Definition: EntityManager.cpp:658
Background2D * GetBackground2D()
Retrieves the 2D background.
Definition: EntityManager.cpp:482
void SetNextJumpStep(Entity *entity)
Calculates and sets the next position during a jump.
Definition: EntityManager.cpp:1375
void OnResize() override
Handles resizing events.
Definition: EntityManager.cpp:420
void AddEntityPoint(const Ogre::String &name, const Ogre::Vector3 &position, const float rotation)
Adds an entity point to the manager.
Definition: EntityManager.cpp:527
void SetNextLinearStep(Entity *entity)
Calculates and sets the next position during a linear movement.
Definition: EntityManager.cpp:1296
void UpdateDebug() override
Updates the entities in the manager with debug information.
Definition: EntityManager.cpp:403
void ClearWorld() override
Clears all world map information in the entity manager.
Definition: EntityManager.cpp:476
Entity * GetEntityFromIndex(const int id) const
Retrieves an entity by it's index in the field.
Definition: EntityManager.cpp:560
static float SideOfVector(const Ogre::Vector2 &point, const Ogre::Vector2 &p1, const Ogre::Vector2 &p2)
Determines at which side of a line a point is.
Definition: EntityManager.cpp:58
std::vector< Entity * > entity_
The list of field or world entities.
Definition: EntityManager.h:616
void ScriptUnsetPlayerEntity()
Unsets any playable entities.
Definition: EntityManager.cpp:621
static float SquareDistanceToLine(const Ogre::Vector3 &point, const Ogre::Vector3 &point_a, const Ogre::Vector3 &point_b, Ogre::Vector3 &proj)
Calculates the square distance between a point and a line.
Definition: EntityManager.cpp:66
void SetNextScrollStep()
Definition: EntityManager.cpp:1400
Entity * GetEntityFromCharacterId(const int id) const
Retrieves an entity by it's assigned character ID.
Definition: EntityManager.cpp:574
void UpdateBattle() override
Updates the battle entities in the manager.
Definition: EntityManager.cpp:294
void SetNextOffsetStep(Entity *entity)
Calculates the next offset step for an entity.
Definition: EntityManager.cpp:1259
An entity point.
Definition: EntityPoint.h:22
Any entity in a field.
Definition: Entity.h:101
A base manager.
Definition: Manager.h:24
A walkmesh.
Definition: Walkmesh.h:68
Ogre::String String
Definition: TypeDefine.h:37
An input event.
Definition: Event.h:84