Skip to content

Commit

Permalink
🚧 Terrain editor can now move preloaded actors.
Browse files Browse the repository at this point in the history
Major changes:
* ActorSpawnRequest can now contain pre-obtained actorInstanceID, the same way as FreeForce request can have pre-obtained ID, the functions are named the same.
* TerrainEditorObject can now reference a live actor instance - used for visualization in editor mode.
* Initial visualization logic for preloaded actors - The visualization still doesn't work for some reason, I tried `RESET_ON_SPOT` paired with `requestTranslation()` but that was created for LiveRepair (aka interactive reset) and doesn't work as needed.

Time:
* This stretched to 2 hours instead of expected 1 and didn't even get the job done.
  • Loading branch information
ohlidalp committed Jan 4, 2025
1 parent 4c975b0 commit b954498
Show file tree
Hide file tree
Showing 15 changed files with 246 additions and 68 deletions.
5 changes: 5 additions & 0 deletions doc/angelscript/Script2Game/GameScriptClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,11 @@ class GameScriptClass
* Number of trucks with flag
*/
int getNumTrucksByFlag(int flag);

/**
* Returns an unused (not reused) ID to use with `MSG_SIM_SPAWN_ACTOR_REQUESTED`; see `game.pushMessage()`.
*/
int getActorNextInstanceId();

///@}

Expand Down
12 changes: 12 additions & 0 deletions doc/angelscript/Script2Game/TerrainEditorObjectClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ class TerrainEditorObjectClass
const vector3 & getRotation();
void setPosition(const vector3&in pos);
void setRotation(const vector3&in rot);

/// @name only for preloaded actors:
/// @{

const SpecialObjectType getSpecialObjectType();
void setSpecialObjectType(SpecialObjectType);

const int getActorInstanceId();
void setActorInstanceId(int);

/// @}

};

/// @} //addtogroup Script2Game
Expand Down
2 changes: 1 addition & 1 deletion doc/angelscript/Script2Game/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ enum MsgType
MSG_SIM_LOAD_TERRN_REQUESTED, //!< Request loading terrain. Param 'filename' (string)
MSG_SIM_LOAD_SAVEGAME_REQUESTED, //!< Request loading saved game. Param 'filename' (string)
MSG_SIM_UNLOAD_TERRN_REQUESTED, //!< Request returning to main menu. No params.
MSG_SIM_SPAWN_ACTOR_REQUESTED, //!< Request spawning an actor. Params: 'filename' (string), 'position' (vector3), 'rotation' (quaternion) 'config' (string, optional), 'skin' (string, optional), 'enter' (bool, optional, default true), , 'free_position' (bool, default false)
MSG_SIM_SPAWN_ACTOR_REQUESTED, //!< Request spawning an actor. Params: 'filename' (string), 'position' (vector3), 'rotation' (quaternion), 'instance_id' (int, optional), 'config' (string, optional), 'skin' (string, optional), 'enter' (bool, optional, default true), , 'free_position' (bool, default false)
MSG_SIM_MODIFY_ACTOR_REQUESTED, //!< Request change of actor. Params: 'type' (enum ActorModifyRequestType)
MSG_SIM_DELETE_ACTOR_REQUESTED, //!< Request actor removal. Params: 'instance_id' (int)
MSG_SIM_SEAT_PLAYER_REQUESTED, //!< Put player character in a vehicle. Params: 'instance_id' (int), use -1 to get out of vehicle.
Expand Down
2 changes: 1 addition & 1 deletion source/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1423,7 +1423,7 @@ int main(int argc, char *argv[])
if (App::sim_state->getEnum<SimState>() == SimState::EDITOR_MODE)
{
App::GetGameContext()->GetTerrain()->GetTerrainEditor()->WriteOutputFile();
App::GetGameContext()->GetTerrain()->GetTerrainEditor()->ClearSelection();
App::GetGameContext()->GetTerrain()->GetTerrainEditor()->ClearSelectedObject();
App::sim_state->setVal((int)SimState::RUNNING);
App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_SYSTEM_NOTICE,
_L("Left terrain editing mode"));
Expand Down
7 changes: 5 additions & 2 deletions source/main/physics/ActorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
using namespace Ogre;
using namespace RoR;

static ActorInstanceID_t m_actor_counter = 1;
const ActorPtr ActorManager::ACTORPTR_NULL; // Dummy value to be returned as const reference.

ActorManager::ActorManager()
Expand All @@ -78,7 +77,11 @@ ActorManager::~ActorManager()

ActorPtr ActorManager::CreateNewActor(ActorSpawnRequest rq, RigDef::DocumentPtr def)
{
ActorPtr actor = new Actor(m_actor_counter++, static_cast<int>(m_actors.size()), def, rq);
if (rq.asr_instance_id == ACTORINSTANCEID_INVALID)
{
rq.asr_instance_id = this->GetActorNextInstanceId();
}
ActorPtr actor = new Actor(rq.asr_instance_id, static_cast<int>(m_actors.size()), def, rq);

if (App::mp_state->getEnum<MpState>() == MpState::CONNECTED && rq.asr_origin != ActorSpawnRequest::Origin::NETWORK)
{
Expand Down
6 changes: 4 additions & 2 deletions source/main/physics/ActorManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class ActorManager
const ActorPtr& FetchNextVehicleOnList(ActorPtr player, ActorPtr prev_player);
const ActorPtr& FetchPreviousVehicleOnList(ActorPtr player, ActorPtr prev_player);
const ActorPtr& FetchRescueVehicle();
ActorInstanceID_t GetActorNextInstanceId() { return m_actor_next_instance_id++; } //!< Script proxy: `game.getActorNextInstanceId()`
/// @}

/// @name Free forces
Expand All @@ -71,7 +72,7 @@ class ActorManager
void ModifyFreeForce(FreeForceRequest* rq);
void RemoveFreeForce(FreeForceID_t id);
FreeForceVec_t::iterator FindFreeForce(FreeForceID_t id);
FreeForceID_t GetFreeForceNextId() { return m_free_force_next_id++; }
FreeForceID_t GetFreeForceNextId() { return m_free_force_next_id++; } //!< Script proxy: `game.getFreeForceNextId()`
/// @}

void UpdateActors(ActorPtr player_actor);
Expand Down Expand Up @@ -142,7 +143,8 @@ class ActorManager
Ogre::Timer m_net_timer;

// Physics
ActorPtrVec m_actors;
ActorPtrVec m_actors; //!< Use `MSG_SIM_{SPAWN/DELETE}_ACTOR_REQUESTED`
ActorInstanceID_t m_actor_next_instance_id = 1; //!< Unique sequential ID for each Actor
bool m_forced_awake = false; //!< disables sleep counters
int m_physics_steps = 0;
float m_dt_remainder = 0.f; //!< Keeps track of the rounding error in the time step calculation
Expand Down
1 change: 1 addition & 0 deletions source/main/physics/SimData.h
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,7 @@ struct ActorSpawnRequest
AI //!< Script controlled
};

ActorInstanceID_t asr_instance_id = ACTORINSTANCEID_INVALID; //!< Optional; see `ActorManager::GetActorNextInstanceID()`;
CacheEntryPtr asr_cache_entry; //!< Optional, overrides 'asr_filename' and 'asr_cache_entry_num'
std::string asr_filename; //!< Can be in "Bundle-qualified" format, i.e. "mybundle.zip:myactor.truck"
Ogre::String asr_config;
Expand Down
8 changes: 8 additions & 0 deletions source/main/scripting/GameScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,9 @@ bool GameScript::pushMessage(MsgType type, AngelScript::CScriptDictionary* dict)
return false;
}

// Set instance ID if specified
GetValueFromScriptDict(log_msg, dict, /*required:*/false, "instance_id", "int", rq->asr_instance_id);

// Set sectionconfig
GetValueFromScriptDict(log_msg, dict, /*required:*/false, "config", "string", rq->asr_config);
// Make sure config exists
Expand Down Expand Up @@ -1786,6 +1789,11 @@ FreeForceID_t GameScript::getFreeForceNextId()
return App::GetGameContext()->GetActorManager()->GetFreeForceNextId();
}

ActorInstanceID_t GameScript::getActorNextInstanceId()
{
return App::GetGameContext()->GetActorManager()->GetActorNextInstanceId();
}

// --------------------------------
// Audio

Expand Down
5 changes: 5 additions & 0 deletions source/main/scripting/GameScript.h
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@ class GameScript

int getNumTrucksByFlag(int flag);

/**
* Returns an unused (not reused) ID to use with `MSG_SIM_SPAWN_ACTOR_REQUESTED`; see `game.pushMessage()`.
*/
ActorInstanceID_t getActorNextInstanceId();

///@}

/// @name FreeForces - see `game.pushMessage()`
Expand Down
1 change: 1 addition & 0 deletions source/main/scripting/bindings/GameScriptAngelscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ void RoR::RegisterGameScript(asIScriptEngine *engine)
result = engine->RegisterObjectMethod("GameScriptClass", "void repairVehicle(const string &in, const string &in, bool)", asMETHOD(GameScript, repairVehicle), asCALL_THISCALL); ROR_ASSERT(result >= 0);
result = engine->RegisterObjectMethod("GameScriptClass", "void removeVehicle(const string &in, const string &in)", asMETHOD(GameScript, removeVehicle), asCALL_THISCALL); ROR_ASSERT(result >= 0);
result = engine->RegisterObjectMethod("GameScriptClass", "int getNumTrucksByFlag(int)", asMETHOD(GameScript, getNumTrucksByFlag), asCALL_THISCALL); ROR_ASSERT(result >= 0);
result = engine->RegisterObjectMethod("GameScriptClass", "int getActorNextInstanceId()", asMETHOD(GameScript, getActorNextInstanceId), asCALL_THISCALL); ROR_ASSERT(result >= 0);

// > FreeForces
result = engine->RegisterObjectMethod("GameScriptClass", "int getFreeForceNextId()", asMETHOD(GameScript, getFreeForceNextId), asCALL_THISCALL); ROR_ASSERT(result >= 0);
Expand Down
3 changes: 3 additions & 0 deletions source/main/scripting/bindings/TerrainAngelscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ void RoR::RegisterTerrain(asIScriptEngine* engine)
result = engine->RegisterObjectMethod("TerrainEditorObjectClass", "const string& getInstanceName()", asMETHOD(RoR::TerrainEditorObject, getInstanceName), asCALL_THISCALL); ROR_ASSERT(result >= 0);
result = engine->RegisterObjectMethod("TerrainEditorObjectClass", "const string& getType()", asMETHOD(RoR::TerrainEditorObject, getType), asCALL_THISCALL); ROR_ASSERT(result >= 0);

// ~ only for preloaded actors:
result = engine->RegisterObjectMethod("TerrainEditorObjectClass", "const SpecialObjectType getSpecialObjectType()", asMETHOD(RoR::TerrainEditorObject, getSpecialObjectType), asCALL_THISCALL); ROR_ASSERT(result >= 0);
result = engine->RegisterObjectMethod("TerrainEditorObjectClass", "void setSpecialObjectType(SpecialObjectType)", asMETHOD(RoR::TerrainEditorObject, setSpecialObjectType), asCALL_THISCALL); ROR_ASSERT(result >= 0);
result = engine->RegisterObjectMethod("TerrainEditorObjectClass", "const int getActorInstanceId()", asMETHOD(RoR::TerrainEditorObject, getActorInstanceId), asCALL_THISCALL); ROR_ASSERT(result >= 0);
result = engine->RegisterObjectMethod("TerrainEditorObjectClass", "void setActorInstanceId(int)", asMETHOD(RoR::TerrainEditorObject, setActorInstanceId), asCALL_THISCALL); ROR_ASSERT(result >= 0);

}
Loading

0 comments on commit b954498

Please sign in to comment.