V-Gears 0
Free Final Fantasy VII engine.
ScriptManager.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 <OgreString.h>
20#include "Event.h"
21#include "LuaIncludes.h"
22#include "Manager.h"
23
24class Entity;
25
29struct ScriptId{
30
34 ScriptId(): entity(""), function(""){}
35
40
45};
46
50struct ScriptEntity;
51
56
61 function(""),
62 argument1(""),
63 argument2(""),
64 priority(0),
65 state(NULL),
67 wait(false),
68 yield(false)
69 {}
70
75
80
85
90
94 lua_State* state;
95
102
107
111 bool wait;
112
116 bool yield;
117
122
127};
128
129
130
131class ScriptManager : public Manager, public Ogre::Singleton<ScriptManager>{
132
133 public:
134
138 enum Type{
139
146
153
160
166 BATTLE
167 };
168
173
177 virtual ~ScriptManager();
178
184 void Input(const VGears::Event& event) override;
185
191 void Update(const Type type);
192
196 void UpdateDebug() override;
197
201 void OnResize() override;
202
206 void ClearField() override;
207
211 void ClearBattle() override;
212
216 void ClearWorld() override;
217
225 void RunString(const Ogre::String& lua);
226
234 void RunFile(const Ogre::String& file);
235
241 void InitBinds();
242
246 void InitCmd();
247
258 void AddEntity(const Type type, const Ogre::String& entity_name, Entity* entity);
259
270 void RemoveEntity(const Type type, const Ogre::String& entity_name);
271
283 const Ogre::String& entity_name, const Ogre::String& function_name, int priority
284 );
285
294
306 luabind::object GetTableByEntityName(
307 const ScriptManager::Type type, const Ogre::String& name, lua_State* state
308 ) const;
309
316 QueueScript* GetScriptByScriptId(const ScriptId& script) const;
317
328 ScriptEntity* GetScriptEntityByName(const Type type, const Ogre::String& entity_name) const;
329
335 const ScriptId GetCurrentScriptId() const;
336
342 void ContinueScriptExecution(const ScriptId& script);
343
350 int ScriptWait(const float seconds);
351
362 void ScriptRequest(
363 const Type type, const char* entity, const char* function, const int priority
364 );
365
376 const Type type, const char* entity, const char* function, const int priority
377 );
378
390 const Type type, const char* entity, const char* function, const int priority
391 );
392
405 bool ScriptRequest(
406 ScriptEntity* script_entity, const Ogre::String& function,
407 const int priority, const Ogre::String& argument1,
408 const Ogre::String& argument2, bool start_sync, bool end_sync
409 );
410
417 void AddValueToStack(const float value);
418
419 private:
420
424 void UpdateField() override;
425
429 void UpdateBattle() override;
430
434 void UpdateWorld() override;
435
439 lua_State* lua_state_;
440
445
450
455
460
464 std::vector<ScriptEntity> script_entity_;
465
470};
471
473
479 ScriptEntity(): name(""), type(ScriptManager::SYSTEM), resort(false){}
480
485
490
494 std::vector<QueueScript> queue;
495
499 bool resort;
500};
501
Any entity in a field.
Definition: Entity.h:101
A base manager.
Definition: Manager.h:24
void Update()
Called every frame, performs an update on the things controlled by the manager.
Definition: Manager.cpp:72
Definition: ScriptManager.h:131
void AddValueToStack(const float value)
Adds a script to the stack.
Definition: ScriptManager.cpp:645
Type
Script types.
Definition: ScriptManager.h:138
@ UI
A UI element script.
Definition: ScriptManager.h:159
@ ENTITY
A field or world map entity script.
Definition: ScriptManager.h:152
@ SYSTEM
System script.
Definition: ScriptManager.h:145
@ BATTLE
A battle entity script.
Definition: ScriptManager.h:166
Ogre::String system_table_name_
The system script table name.
Definition: ScriptManager.h:444
Ogre::String battle_table_name_
The battle entity script table name.
Definition: ScriptManager.h:454
void ClearField() override
Clears all field information in the script manager.
Definition: ScriptManager.cpp:323
virtual ~ScriptManager()
Destructor.
Definition: ScriptManager.cpp:66
int ScriptRequestEndSync(const Type type, const char *entity, const char *function, const int priority)
Request a synchronous script execution to end.
Definition: ScriptManager.cpp:572
void AddEntityScript(const Ogre::String &entity_name, const Ogre::String &function_name, int priority)
Adds an script to an entity.
void ClearBattle() override
Clears all battle information in the script manager.
Definition: ScriptManager.cpp:325
void InitBinds()
Initializes Lua binds.
Definition: ScriptManagerBinds.h:82
void RunString(const Ogre::String &lua)
Runs a lua command string.
Definition: ScriptManager.cpp:339
void ScriptRequest(const Type type, const char *entity, const char *function, const int priority)
Request an script execution.
Definition: ScriptManager.cpp:516
void UpdateBattle() override
Updates the scripts during a battle.
Definition: ScriptManager.cpp:652
void ClearWorld() override
Clears all world map information in the script manager.
Definition: ScriptManager.cpp:337
void ContinueScriptExecution(const ScriptId &script)
continues the execution of a script.
Definition: ScriptManager.cpp:489
void InitCmd()
Initializes command bindings.
Definition: ScriptManagerCommands.h:55
void UpdateWorld() override
Updates the scripts while on the world map.
Definition: ScriptManager.cpp:654
std::vector< ScriptEntity > script_entity_
The list of map entity scripts.
Definition: ScriptManager.h:464
void Input(const VGears::Event &event) override
Handles an input event.
Definition: ScriptManager.cpp:68
int ScriptRequestStartSync(const Type type, const char *entity, const char *function, const int priority)
Request a synchronous script execution to start.
Definition: ScriptManager.cpp:542
const ScriptId GetCurrentScriptId() const
Retrieves the current script ID.
Definition: ScriptManager.cpp:487
int ScriptWait(const float seconds)
Makes an script wait.
Definition: ScriptManager.cpp:501
ScriptEntity * GetScriptEntityByName(const Type type, const Ogre::String &entity_name) const
Retrieves a script entity by it's name and type.
Definition: ScriptManager.cpp:477
lua_State * lua_state_
Lua state.
Definition: ScriptManager.h:439
ScriptId current_script_id_
The current script ID.
Definition: ScriptManager.h:469
void RemoveEntity(const Type type, const Ogre::String &entity_name)
Deletes an entity from the manager.
Definition: ScriptManager.cpp:417
luabind::object GetTableByEntityName(const ScriptManager::Type type, const Ogre::String &name, lua_State *state) const
Retrieves a table.
Definition: ScriptManager.cpp:441
void RunFile(const Ogre::String &file)
Runs a lua file.
Definition: ScriptManager.cpp:355
void UpdateDebug() override
Updates the script in the manager with debug information.
Definition: ScriptManager.cpp:319
Ogre::String entity_table_name_
The entity script table name.
Definition: ScriptManager.h:449
void UpdateField() override
Updates the script while in a field.
Definition: ScriptManager.cpp:650
QueueScript * GetScriptByScriptId(const ScriptId &script) const
Retrieves a script from it's ID.
Definition: ScriptManager.cpp:464
void RemoveEntityTopScript(ScriptEntity &entity)
Removes the top script of an entity.
Definition: ScriptManager.cpp:428
Ogre::String ui_table_name_
The UI script table name.
Definition: ScriptManager.h:459
void OnResize() override
Handles resizing events.
Definition: ScriptManager.cpp:321
ScriptManager()
Constructor.
Definition: ScriptManager.cpp:48
void AddEntity(const Type type, const Ogre::String &entity_name, Entity *entity)
Adds an entity to the manager.
Definition: ScriptManager.cpp:360
Ogre::String String
Definition: TypeDefine.h:37
A script queue.
Definition: ScriptManager.h:55
int priority
Function priority.
Definition: ScriptManager.h:89
ScriptId paused_script_start
The script paused by call of this script.
Definition: ScriptManager.h:121
float seconds_to_wait
Seconds to wait for completion.
Definition: ScriptManager.h:106
bool wait
Indicates if the script completion should be waited for,.
Definition: ScriptManager.h:111
Ogre::String argument1
First function argument.
Definition: ScriptManager.h:79
Ogre::String argument2
Second function argument.
Definition: ScriptManager.h:84
int state_id
State thread identifier.
Definition: ScriptManager.h:101
lua_State * state
Current state.
Definition: ScriptManager.h:94
Ogre::String function
Function name.
Definition: ScriptManager.h:74
ScriptId paused_script_end
The script paused by call of this script.
Definition: ScriptManager.h:126
QueueScript()
Constructor.
Definition: ScriptManager.h:60
bool yield
Definition: ScriptManager.h:116
Definition: ScriptManager.h:472
ScriptEntity()
Constructor.
Definition: ScriptManager.h:479
ScriptManager::Type type
The script type.
Definition: ScriptManager.h:489
Ogre::String name
The script name.
Definition: ScriptManager.h:484
std::vector< QueueScript > queue
The script queue.
Definition: ScriptManager.h:494
bool resort
Definition: ScriptManager.h:499
Script identifier.
Definition: ScriptManager.h:29
Ogre::String entity
Entity name.
Definition: ScriptManager.h:39
ScriptId()
Constructor.
Definition: ScriptManager.h:34
Ogre::String function
Function (script) name.
Definition: ScriptManager.h:44
An input event.
Definition: Event.h:84