Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AngelScript: fixed ref counting, added ProceduralRoad API #2930

Closed
wants to merge 9 commits into from
5 changes: 5 additions & 0 deletions doc/angelscript/Script2Game/GameScriptClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,11 @@ class GameScriptClass
* This method repairs the vehicle in the box
*/
void repairVehicle(string instance, string box, bool keepPosition);

/**
* Gets the currently loaded terrain instance
*/
TerrainClass@ getTerrain();

/**
* This method removes the vehicle in the box
Expand Down
37 changes: 37 additions & 0 deletions doc/angelscript/Script2Game/ProceduralManagerClass.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

namespace Script2Game {

/** \addtogroup ScriptSideAPIs
* @{
*/

/** \addtogroup Script2Game
* @{
*/

/**
* @brief Binding of RoR::ProceduralManager; generates dynamic roads for terrain.
* @note Obtain the object using `game.getTerrain().getProceduralManager()`.
*/
class ProceduralManagerClass
{
public:
/**
* Generates road mesh and adds to internal list
*/
void addObject(ProceduralObjectClass @po);

/**
* Clears road mesh and removes from internal list
*/
void removeObject(ProceduralObjectClass @po);

int getNumObjects();

ProceduralObjectClass@ getObject(int pos);
};

/// @} //addtogroup Script2Game
/// @} //addtogroup ScriptSideAPIs

} //namespace Script2Game
41 changes: 41 additions & 0 deletions doc/angelscript/Script2Game/ProceduralObjectClass.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

namespace Script2Game {

/** \addtogroup ScriptSideAPIs
* @{
*/

/** \addtogroup Script2Game
* @{
*/

/**
* @brief Binding of RoR::ProceduralObject; a spline for generating dynamic roads.
*/
class ProceduralObjectClass
{
public:
/**
* Name of the road/street this spline represents.
*/
string name;

/**
* Adds point at the end.
*/
void addPoint(procedural_point);

/**
* Adds point before the element at the specified position.
*/
void insertPoint(int pos, procedural_point);
void deletePoint(int pos);
procedural_point getPoint(int pos);
int getNumPoints();
ProceduralRoadClass @getRoad();
};

/// @} //addtogroup Script2Game
/// @} //addtogroup ScriptSideAPIs

} //namespace Script2Game
30 changes: 30 additions & 0 deletions doc/angelscript/Script2Game/ProceduralPointClass.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

namespace Script2Game {

/** \addtogroup ScriptSideAPIs
* @{
*/

/** \addtogroup Script2Game
* @{
*/

/**
* @brief Binding of RoR::ProceduralPoint;
*/
struct ProceduralPointClass
{
public:
vector3 position;
quaternion rotation;
float width;
float border_width;
float border_height;
RoadType type;
int pillar_type;
};

/// @} //addtogroup Script2Game
/// @} //addtogroup ScriptSideAPIs

} //namespace Script2Game
75 changes: 75 additions & 0 deletions doc/angelscript/Script2Game/ProceduralRoadClass.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@

namespace Script2Game {

/** \addtogroup ScriptSideAPIs
* @{
*/

/** \addtogroup Script2Game
* @{
*/

enum RoadType
{
ROAD_AUTOMATIC,
ROAD_FLAT,
ROAD_LEFT,
ROAD_RIGHT,
ROAD_BOTH,
ROAD_BRIDGE,
ROAD_MONORAIL
};

enum TextureFit
{
TEXFIT_NONE,
TEXFIT_BRICKWALL,
TEXFIT_ROADS1,
TEXFIT_ROADS2,
TEXFIT_ROAD,
TEXFIT_ROADS3,
TEXFIT_ROADS4,
TEXFIT_CONCRETEWALL,
TEXFIT_CONCRETEWALLI,
TEXFIT_CONCRETETOP,
TEXFIT_CONCRETEUNDER
};

/**
* @brief Binding of RoR::ProceduralRoad; a dynamically generated road mesh.
* @note For internal use by ProceduralManagerClass - do not use unless you know what you're doing!
*/
*/
class ProceduralRoadClass
{
public:
/**
* For internal use by ProceduralManagerClass - do not use unless you know what you're doing!
*/
void addBlock(vector3 pos, quaternion rot, RoadType type, float width, float border_width, float border_height, int pillar_type = 1);
/**
* For internal use by ProceduralManagerClass - do not use unless you know what you're doing!
*/
void addQuad(vector3 p1, vector3 p2, vector3 p3, vector3 p4, TextureFit texfit, vector3 pos, vector3 lastpos, float width, bool flip = false);
/**
* For internal use by ProceduralManagerClass - do not use unless you know what you're doing!
*/
void addCollisionQuad(vector3 p1, vector3 p2, vector3 p3, vector3 p4, string const&in gm_name, bool flip = false);
/**
* For internal use by ProceduralManagerClass - do not use unless you know what you're doing!
*/
void createMesh();
/**
* For internal use by ProceduralManagerClass - do not use unless you know what you're doing!
*/
void finish();
/**
* For internal use by ProceduralManagerClass - do not use unless you know what you're doing!
*/
void setCollisionEnabled(bool v);
};

/// @} //addtogroup Script2Game
/// @} //addtogroup ScriptSideAPIs

} //namespace Script2Game
50 changes: 50 additions & 0 deletions doc/angelscript/Script2Game/TerrainClass.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

namespace Script2Game {

/** \addtogroup ScriptSideAPIs
* @{
*/

/** \addtogroup Script2Game
* @{
*/

/**
* @brief Binding of RoR::Terrain; represents a loaded terrain.
* @note Obtain the object using `game.getTerrain()`.
*/
class TerrainClass
{
public:
/**
* @return Full name of the terrain
*/
string getTerrainName();

/**
* @return GUID (global unique ID) of the terrain, or empty string if not specified.
*/
string getGUID();

/**
* @return true if specified as flat (no heightmap).
*/
bool isFlat();

/**
* @return version of the terrain, as specified by author.
*/
int getVersion();

/**
* @return Player spawn position when entering game.
*/
vector3 getSpawnPos();

ProceduralManagerClass @getProceduralManager();
};

/// @} //addtogroup Script2Game
/// @} //addtogroup ScriptSideAPIs

} //namespace Script2Game
4 changes: 2 additions & 2 deletions source/main/AppContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void AppContext::windowResized(Ogre::RenderWindow* rw)
App::GetOverlayWrapper()->windowResized();
if (App::sim_state->getEnum<AppState>() == RoR::AppState::SIMULATION)
{
for (Actor* actor: App::GetGameContext()->GetActorManager()->GetActors())
for (ActorPtr& actor: App::GetGameContext()->GetActorManager()->GetActors())
{
actor->ar_dashboard->windowResized();
}
Expand Down Expand Up @@ -357,7 +357,7 @@ void AppContext::CaptureScreenshot()
png.addData("Truck_file", App::GetGameContext()->GetPlayerActor()->ar_filename);
png.addData("Truck_name", App::GetGameContext()->GetPlayerActor()->getTruckName());
}
if (App::GetSimTerrain())
if (App::GetGameContext()->GetTerrain())
{
png.addData("Terrn_file", App::sim_terrain_name->getStr());
png.addData("Terrn_name", App::sim_terrain_gui_name->getStr());
Expand Down
4 changes: 1 addition & 3 deletions source/main/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "Network.h"
#include "ScriptEngine.h"
#include "SoundScriptManager.h"
#include "Terrain.h"
#include "ThreadPool.h"

namespace RoR {
Expand All @@ -60,7 +61,6 @@ static GUIManager* g_gui_manager;
static InputEngine* g_input_engine;
static CacheSystem* g_cache_system;
static MumbleIntegration* g_mumble;
static Terrain* g_sim_terrain;
static ThreadPool* g_thread_pool;
static CameraManager* g_camera_manager;
static GfxScene g_gfx_scene;
Expand Down Expand Up @@ -237,7 +237,6 @@ CVar* gfx_reduce_shadows;
CVar* gfx_enable_rtshaders;

// Instance management
void SetSimTerrain (Terrain* obj) { g_sim_terrain = obj;}
void SetCacheSystem (CacheSystem* obj) { g_cache_system = obj; }

// Instance access
Expand All @@ -249,7 +248,6 @@ Console* GetConsole () { return &g_console;}
InputEngine* GetInputEngine () { return g_input_engine;}
CacheSystem* GetCacheSystem () { return g_cache_system;}
MumbleIntegration* GetMumble () { return g_mumble; }
Terrain* GetSimTerrain () { return g_sim_terrain; }
ThreadPool* GetThreadPool () { return g_thread_pool; }
CameraManager* GetCameraManager () { return g_camera_manager; }
GfxScene* GetGfxScene () { return &g_gfx_scene; }
Expand Down
10 changes: 4 additions & 6 deletions source/main/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ enum MsgType
MSG_SIM_UNLOAD_TERRN_REQUESTED,
MSG_SIM_SPAWN_ACTOR_REQUESTED, //!< Payload = RoR::ActorSpawnRequest* (owner)
MSG_SIM_MODIFY_ACTOR_REQUESTED, //!< Payload = RoR::ActorModifyRequest* (owner)
MSG_SIM_DELETE_ACTOR_REQUESTED, //!< Payload = RoR::Actor* (weak)
MSG_SIM_SEAT_PLAYER_REQUESTED, //!< Payload = RoR::Actor* (weak) | nullptr
MSG_SIM_DELETE_ACTOR_REQUESTED, //!< Payload = RoR::ActorPtr* (owner)
MSG_SIM_SEAT_PLAYER_REQUESTED, //!< Payload = RoR::ActorPtr (owner) | nullptr
MSG_SIM_TELEPORT_PLAYER_REQUESTED, //!< Payload = Ogre::Vector3* (owner)
MSG_SIM_HIDE_NET_ACTOR_REQUESTED, //!< Payload = Actor* (weak)
MSG_SIM_UNHIDE_NET_ACTOR_REQUESTED, //!< Payload = Actor* (weak)
MSG_SIM_HIDE_NET_ACTOR_REQUESTED, //!< Payload = ActorPtr* (owner)
MSG_SIM_UNHIDE_NET_ACTOR_REQUESTED, //!< Payload = ActorPtr* (owner)
// GUI
MSG_GUI_OPEN_MENU_REQUESTED,
MSG_GUI_CLOSE_MENU_REQUESTED,
Expand Down Expand Up @@ -442,7 +442,6 @@ Console* GetConsole();
InputEngine* GetInputEngine();
CacheSystem* GetCacheSystem();
MumbleIntegration* GetMumble();
Terrain* GetSimTerrain();
ThreadPool* GetThreadPool();
CameraManager* GetCameraManager();
GfxScene* GetGfxScene();
Expand All @@ -466,7 +465,6 @@ void CreateSoundScriptManager();
void CreateScriptEngine();

// Setters
void SetSimTerrain (Terrain* obj);
void SetCacheSystem (CacheSystem* obj);

// Cleanups
Expand Down
5 changes: 5 additions & 0 deletions source/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ set(SOURCE_FILES
terrain/Terrain.{h,cpp}
terrain/TerrainObjectManager.{h,cpp}
threadpool/ThreadPool.h
utils/memory/RefCountingObject.h
utils/memory/RefCountingObjectPtr.h
utils/ConfigFile.{h,cpp}
utils/ErrorUtils.{h,cpp}
utils/ForceFeedback.{h,cpp}
Expand Down Expand Up @@ -232,7 +234,9 @@ if (USE_ANGELSCRIPT)
scripting/bindings/InputEngineAngelscript.cpp
scripting/bindings/LocalStorageAngelscript.cpp
scripting/bindings/OgreAngelscript.cpp
scripting/bindings/ProceduralRoadAngelscript.cpp
scripting/bindings/ScriptEventsAngelscript.cpp
scripting/bindings/TerrainAngelscript.cpp
scripting/bindings/VehicleAiAngelscript.cpp
)
endif ()
Expand Down Expand Up @@ -344,6 +348,7 @@ target_include_directories(${BINNAME} PRIVATE
terrain
terrain/map
threadpool
utils/memory
utils
)

Expand Down
14 changes: 14 additions & 0 deletions source/main/ForwardDeclarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
/// @author Petr Ohlidal
/// @date 12/2013

#include "RefCountingObjectPtr.h"

#pragma once

Expand Down Expand Up @@ -83,6 +84,10 @@ namespace RoR
class OgreSubsystem;
struct PlatformUtils;
class PointColDetector;
class ProceduralManager;
struct ProceduralObject;
struct ProceduralPoint;
class ProceduralRoad;
struct Prop;
struct PropAnim;
class RailGroup;
Expand Down Expand Up @@ -141,6 +146,15 @@ namespace RoR
struct client_t;
struct authorinfo_t;

// AngelScript-friendly shared pointers
typedef RefCountingObjectPtr<Actor> ActorPtr;
typedef RefCountingObjectPtr<VehicleAI> VehicleAIPtr;
typedef RefCountingObjectPtr<Terrain> TerrainPtr;
typedef RefCountingObjectPtr<ProceduralPoint> ProceduralPointPtr;
typedef RefCountingObjectPtr<ProceduralObject> ProceduralObjectPtr;
typedef RefCountingObjectPtr<ProceduralRoad> ProceduralRoadPtr;
typedef RefCountingObjectPtr<ProceduralManager> ProceduralManagerPtr;

namespace GUI
{
class ConsoleView;
Expand Down
Loading