Skip to content

Commit

Permalink
Update code to work with updated openrct2
Browse files Browse the repository at this point in the history
  • Loading branch information
Basssiiie committed Jun 12, 2024
1 parent bc87765 commit fd5ea84
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 44 deletions.
1 change: 0 additions & 1 deletion src/openrct2-bindings/Bindings/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ extern "C"
rct2path);

// Create a plain context
Platform::CoreInit();
unityContext = CreateContext(); // OpenRCT2::CreateContext()
bool result = unityContext->Initialise();

Expand Down
49 changes: 17 additions & 32 deletions src/openrct2-bindings/Map/Surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,57 +12,42 @@ extern "C"
{
struct SurfaceInfo
{
uint32_t surfaceIndex;
uint32_t edgeIndex;
uint32_t surfaceImageIndex;
uint32_t edgeImageIndex;
int32_t waterHeight;
uint8_t slope;
};

// Returns the sprite image index for a surface sprite.
// Inspired by: GetSurfaceObject(), GetSurfaceImage()
uint32_t GetSurfaceImageIndex(const TileElement* element, const SurfaceElement* surface, int32_t x, int32_t y)
static uint32_t GetSurfaceImageIndex(const TileElement* element, const SurfaceElement* surface, int32_t x, int32_t y)
{
uint32_t surfaceIndex = surface->GetSurfaceStyle();
uint8_t grassLength = surface->GetGrassLength();
ImageId imageId;

IObjectManager& objMgr = OpenRCT2::GetContext()->GetObjectManager();
Object* obj = objMgr.GetLoadedObject(ObjectType::TerrainSurface, surfaceIndex);

if (obj == nullptr)
const TerrainSurfaceObject* surfaceObject = surface->GetSurfaceObject();
if (surfaceObject == nullptr)
{
dll_log("Could not find surface object: %i", surfaceIndex);
return 0;
}
else
{
const TerrainSurfaceObject* result = static_cast<TerrainSurfaceObject*>(obj);

imageId = ImageId(result->GetImageId({ x, y }, grassLength, element->GetDirection(), 0, false, false));
if (result->Colour != 255)
uint8_t grassLength = surface->GetGrassLength();
auto imageId = ImageId(surfaceObject->GetImageId({ x, y }, grassLength, element->GetDirection(), 0, false, false));
if (surfaceObject->Colour != 255)
{
imageId = imageId.WithPrimary(result->Colour);
imageId = imageId.WithPrimary(surfaceObject->Colour);
}
}
return imageId.ToUInt32();
}

// Returns the sprite image for a surface edge sprite.
// Inspired by: GetEdgeImageWithOffset()
uint32_t GetSurfaceEdgeImageIndex(const SurfaceElement* surface)
{
uint32_t edgeIndex = surface->GetEdgeStyle();

IObjectManager& objMgr = OpenRCT2::GetContext()->GetObjectManager();
Object* obj = objMgr.GetLoadedObject(ObjectType::TerrainEdge, edgeIndex);

if (obj == nullptr)
static uint32_t GetSurfaceEdgeImageIndex(const SurfaceElement* surface)
{
const TerrainEdgeObject* edgeObject = surface->GetEdgeObject();
if (edgeObject == nullptr)
{
dll_log("Could not find surface edge object: %i", edgeIndex);
return 0;
}

auto tobj = static_cast<TerrainEdgeObject*>(obj);
return tobj->BaseImageId + 5; // EDGE_BOTTOMRIGHT = +5
return edgeObject->BaseImageId + 5; // EDGE_BOTTOMRIGHT = +5
}

// Writes the surface element details to the specified buffer.
Expand All @@ -77,8 +62,8 @@ extern "C"
return;
}

element->surfaceIndex = GetSurfaceImageIndex(source, surface, x, y);
element->edgeIndex = GetSurfaceEdgeImageIndex(surface);
element->surfaceImageIndex = GetSurfaceImageIndex(source, surface, x, y);
element->edgeImageIndex = GetSurfaceEdgeImageIndex(surface);
element->slope = surface->GetSlope();
element->waterHeight = surface->GetWaterHeight();
}
Expand Down
5 changes: 0 additions & 5 deletions src/openrct2-bindings/Map/TileElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ extern "C"
// Writes all tile-elements at the the specified coordinates to the specified buffer.
EXPORT int GetMapElementsAt(int x, int y, TileElementInfo* elements, int arraySize)
{
dll_log("Cpp TileElementInfo size: %li", sizeof(TileElementInfo));

const TileElement* source = GetTileElementAt(x, y, 0);
int elementCount = 0;

Expand All @@ -42,9 +40,6 @@ extern "C"
SetTileElementInfo(&elements[i], source);
elementCount++;

const uint32_t* ptr = (uint32_t*)&elements[i];
dll_log("%i -> %08x %08x\n", 1, ptr[1], ptr[0]);

if (source->IsLastForTile())
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class GameEditor : UnityEditor.Editor
const string _defaultOpenRCT2Path = @"bin\data"; // from repo root
const string _defaultParkPath = @"Parks"; // from unity project/executable root

static readonly string[] _validParkExtensions = { ".sv6", ".sc6", ".sv4", ".sc4" };
static readonly string[] _validParkExtensions = { ".park", ".sv6", ".sc6", ".sv4", ".sc4" };


bool _groupToggleDataPaths = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ namespace OpenRCT2.Bindings.TileElements
{
public readonly struct SurfaceInfo
{
public readonly uint surfaceIndex;
public readonly uint edgeIndex;
public readonly uint surfaceImageIndex;
public readonly uint edgeImageIndex;

public readonly int waterHeight;
public readonly SurfaceSlope slope;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void CreateSurfaceElement(MeshBuilder builder, List<int> materialIndices, int x,
*/

SurfaceInfo surface = tile.surface;
int surfaceSubmesh = AddMaterialIndex(materialIndices, PushImageIndex(surface.surfaceIndex, TextureType.Surface));
int surfaceSubmesh = AddMaterialIndex(materialIndices, PushImageIndex(surface.surfaceImageIndex, TextureType.Surface));

SurfaceSlope slope = surface.slope;
int baseHeight = tile.baseHeight;
Expand Down Expand Up @@ -218,7 +218,7 @@ void CreateSurfaceElement(MeshBuilder builder, List<int> materialIndices, int x,
}

// Edges
uint edgeImage = surface.edgeIndex;
uint edgeImage = surface.edgeImageIndex;
// HACK: only add the material stack index when any of the add-edges succeed.
// Otherwise it will create inconsistency in materials, because some may not be used.
int materialStackIndex = PushImageIndex(edgeImage, TextureType.Edge);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void CreateElement(in MapData map, int x, int y, int index, in TileElemen
position.y += trackOffset;

GameObject obj = UnityEngine.Object.Instantiate(_prefab, position, Quaternion.Euler(0, element.rotation * 90f, 0), map.transform);
obj.name = $"Track [{x}, {y}] type: {trackType}, key: {meshKey:x}, colours: ({track.mainColour}, {track.additionalColour}, {track.supportsColour}), rot: {element.rotation}, inv: {track.inverted}";
obj.name = $"Track [{x}, {y}, {element.baseHeight}] type: {trackType}, key: {meshKey:x}, colours: ({track.mainColour}, {track.additionalColour}, {track.supportsColour}), rot: {element.rotation}, inv: {track.inverted}";
obj.isStatic = true;

MeshFilter filter = obj.GetComponent<MeshFilter>();
Expand Down

0 comments on commit fd5ea84

Please sign in to comment.