Skip to content

Commit

Permalink
CameraOperator in the scene
Browse files Browse the repository at this point in the history
  • Loading branch information
gleblebedev committed May 2, 2024
1 parent 2188538 commit 90a128c
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
]
},
"unofficial.Urho3DNet.Editor": {
"version": "0.3.7.792",
"version": "0.3.7.800",
"commands": [
"rbfx"
]
Expand Down
14 changes: 10 additions & 4 deletions Content/Common/Data/Scenes/Scene.scene
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<resource _id="1">
<attributes>
<attribute name="Next Node ID" type="Int" value="29" />
<attribute name="Next Component ID" type="Int" value="63" />
<attribute name="Next Component ID" type="Int" value="74" />
</attributes>
<components>
<component _id="1" _typeName="Octree" />
Expand All @@ -21,7 +21,7 @@
<attribute name="Type" type="String" value="Music" />
<attribute name="Frequency" type="Float" value="48000.000000" />
<attribute name="Is Playing" type="Bool" value="true" />
<attribute name="Play Position" type="Int" value="-1550372864" />
<attribute name="Play Position" type="Int" value="202423472" />
</attributes>
</component>
</components>
Expand Down Expand Up @@ -73,7 +73,7 @@
<node _id="7">
<attributes>
<attribute name="Name" type="String" value="Main Camera" />
<attribute name="Position" type="Vector3" value="0 2 0" />
<attribute name="Position" type="Vector3" value="2.98023e-08 2 1.19209e-06" />
<attribute name="Rotation" type="Quaternion" value="0.707107 0.707107 0 0" />
</attributes>
<components>
Expand All @@ -82,7 +82,13 @@
<attribute name="Near Clip" type="Float" value="0.000000" />
<attribute name="Far Clip" type="Float" value="10.000000" />
<attribute name="Orthographic" type="Bool" value="true" />
<attribute name="Orthographic Size" type="Float" value="5.000000" />
<attribute name="Orthographic Size" type="Float" value="2.200000" />
</attributes>
</component>
<component _id="73" _typeName="CameraOperator">
<attributes>
<attribute name="Padding" type="Vector4" value="0.1 0.1 0.1 0.1" />
<attribute name="Track Bounding Box" type="Bool" value="true" />
</attributes>
</component>
</components>
Expand Down
32 changes: 1 addition & 31 deletions Content/Common/Data/UI/Options.rml
Original file line number Diff line number Diff line change
Expand Up @@ -36,43 +36,13 @@
</style>
</head>

<body data-model="MenuComponent" style="width: 100%; height: 100%; margin: 0; decorator: image(../Images/Background.png); nav: auto">
<body data-model="GameRmlUIComponent" style="width: 100%; height: 100%; margin: 0; decorator: image(../Images/Background.png); nav: auto">
<div class="gray-inner-panel menu-panel" style="top: 50%; left: 50%; position: absolute; transform: translate(-50%, -50%); max-height: 90%; max-height: 90%; min-width: 800px">
<div style="text-align: center">Settings</div>
<br/>
<table>
<col style="text-align: right; "/>
<col style="text-align: left; "/>
<tr>
<td>
<label for="bloom">Bloom</label>
</td>
<td>
<input id="bloom" type="checkbox" class="blue-checkbox" data-checked="bloom"/>
</td>
</tr>
<tr>
<td>
<label for="ssao">SSAO</label>
</td>
<td>
<input id="ssao" type="checkbox" class="blue-checkbox" data-checked="ssao" />
</td>
</tr>
<!--<tr>
<td>
<label for="shadow">Shadow quality</label>
</td>
<td>
<navigable group="main_menu_group" onnavigated="sound:Sounds/UINavigated.wav" onpressed="sound:Sounds/UIClicked.wav" style="display: block">
<select id="shadow" class="blue-button" data-value="shadows" style="width: 300px; display: inline-block;">
<option value="0">Low</option>
<option value="1">Medium</option>
<option value="2">High</option>
</select>
</navigable>
</td>
</tr>-->
<tr>
<td>
<label for="musmasteric">Master</label>
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<Urho3DNetVersion>0.3.7.792</Urho3DNetVersion>
<Urho3DNetVersion>0.3.7.800</Urho3DNetVersion>
</PropertyGroup>
</Project>
46 changes: 46 additions & 0 deletions RbfxTemplate/GameSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Urho3DNet;

namespace RbfxTemplate
{
/// <summary>
/// Settings file content.
/// </summary>
public class GameSettings
{
private static readonly string SOUND_MASTER = "Master";

private static readonly string SOUND_EFFECT = "Effect";

//static readonly string SOUND_AMBIENT = "Ambient";
//static readonly string SOUND_VOICE = "Voice";
private static readonly string SOUND_MUSIC = "Music";

/// <summary>
/// Get or set master volume.
/// </summary>
public float MasterVolume { get; set; } = 1.0f;

/// <summary>
/// Get or set music volume.
/// </summary>
public float MusicVolume { get; set; } = 1.0f;

/// <summary>
/// Get or set effects volume.
/// </summary>
public float EffectVolume { get; set; } = 1.0f;

/// <summary>
/// Apply settings to the application global settings.
/// </summary>
/// <param name="context">Application context.</param>
public void Apply(Context context)
{
var audio = context.GetSubsystem<Audio>();

audio.SetMasterGain(SOUND_MASTER, MasterVolume);
audio.SetMasterGain(SOUND_MUSIC, MusicVolume);
audio.SetMasterGain(SOUND_EFFECT, EffectVolume);
}
}
}
10 changes: 4 additions & 6 deletions RbfxTemplate/GameState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public sealed class GameState : RmlUIStateBase
private readonly UrhoPluginApplication _app;
private readonly Node _cameraNode;
private readonly Camera _camera;
private readonly CameraOperator _cameraOperator;
private readonly Viewport _viewport;
private readonly PrefabResource _tilePrefab;

Expand Down Expand Up @@ -59,7 +60,6 @@ public sealed class GameState : RmlUIStateBase
private readonly PhysicsRaycastResult _raycastResult;
private readonly Material _baseMaterial;
private StateBase _state;

Check warning on line 62 in RbfxTemplate/GameState.cs

View workflow job for this annotation

GitHub Actions / build_uwp

The field 'GameState._state' is never used

Check warning on line 62 in RbfxTemplate/GameState.cs

View workflow job for this annotation

GitHub Actions / build_desktop (macos-13)

The field 'GameState._state' is never used

Check warning on line 62 in RbfxTemplate/GameState.cs

View workflow job for this annotation

GitHub Actions / build_android

The field 'GameState._state' is never used

Check warning on line 62 in RbfxTemplate/GameState.cs

View workflow job for this annotation

GitHub Actions / build_desktop (windows-latest)

The field 'GameState._state' is never used

Check warning on line 62 in RbfxTemplate/GameState.cs

View workflow job for this annotation

GitHub Actions / build_desktop (ubuntu-latest)

The field 'GameState._state' is never used
private Vector2 _areaSize = new Vector2(1, 1);

private int _levelIndex;
private int _hintsLeft = 2;
Expand All @@ -84,6 +84,7 @@ public GameState(UrhoPluginApplication app) : base(app, "UI/GameScreen.rml")
_cameraNode = _scene.Ptr.GetChild("Main Camera");
_viewport = Context.CreateObject<Viewport>();
_camera = _cameraNode?.GetComponent<Camera>();
_cameraOperator = _cameraNode?.GetComponent<CameraOperator>();
_viewport.Camera = _camera;
_viewport.Scene = _scene;
SetViewport(0, _viewport);
Expand Down Expand Up @@ -148,10 +149,6 @@ public override void Activate(StringVariantMap bundle)
public override void Update(float timeStep)
{
_stateManager.State.Update(timeStep);

var orthoSizeY = _areaSize.Y;
var orthoSizeX = _areaSize.X * UI.Size.Y / UI.Size.X;
_camera.OrthoSize = Math.Max(orthoSizeX, orthoSizeY);
}

public override void Deactivate()
Expand Down Expand Up @@ -211,7 +208,8 @@ public void AddPairs(int numTiles)
rightTiles[index].Position = pos + new Vector3(d, 0, index * d);
}

_areaSize = new Vector2(5, (leftTiles.Count + 1) * d);
var size = new Vector3(5, 1, (leftTiles.Count + 1) * d);
_cameraOperator.BoundingBox = new BoundingBox(size*-0.5f, size*0.5f);
}

public Tile CreateTile(string imageName)
Expand Down
56 changes: 56 additions & 0 deletions RbfxTemplate/SettingsMenuState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Urho3DNet;

namespace RbfxTemplate
{
public class SettingsMenuState : RmlUIStateBase
{
public SettingsMenuState(UrhoPluginApplication app) : base(app, "UI/Options.rml")
{
Settings = app.Settings;
}

public GameSettings Settings { get; private set; }

public override void OnDataModelInitialized(GameRmlUIComponent menuComponent)
{
menuComponent.BindDataModelEvent("Apply", OnApply);
menuComponent.BindDataModelEvent("Cancel", OnCancel);
menuComponent.BindDataModelProperty("master", val => val.Set(Settings.MasterVolume),
val => Settings.MasterVolume = val.Float);
menuComponent.BindDataModelProperty("music", val => val.Set(Settings.MusicVolume),
val => Settings.MusicVolume = val.Float);
menuComponent.BindDataModelProperty("effects", val => val.Set(Settings.EffectVolume),
val => Settings.EffectVolume = val.Float);
//menuComponent.BindDataModelProperty("shadows", val => val.Set(_shadowsQuality), (val) => _shadowsQuality = val.Convert(VariantType.VarInt).Int);
}

public override void Activate(StringVariantMap bundle)
{
Settings = Application.Settings;

var audio = Context.GetSubsystem<Audio>();

base.Activate(bundle);
}

public override void Deactivate()
{
base.Deactivate();
}

private void OnCancel(VariantList obj)
{
Application.HandleBackKey();

//Application.Settings = GameSettings.Load(Context);
}

private void OnApply(VariantList obj)
{
Settings.Apply(Context);
//Settings.Save(Context);

Application.HandleBackKey();
}
}
}
46 changes: 42 additions & 4 deletions RbfxTemplate/UrhoApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,52 @@ public override void Setup()
EngineParameters[Urho3D.EpConfigName] = "";
EngineParameters[Urho3D.EpOrientations] = "LandscapeLeft LandscapeRight Portrait";

// Run shaders via SpirV-Cross to eliminate potential driver bugs
//EngineParameters[Urho3D.EpShaderPolicy] = 0;
// Enable this if you need to debug translated shaders.
//EngineParameters[Urho3D.EpShaderLogSources] = true;
ApplyCommandLineArguments();

base.Setup();
}

private void ApplyCommandLineArguments()
{
try
{
var commandLineArgs = Environment.GetCommandLineArgs();
for (var index = 0; index < commandLineArgs.Length; index++)
{
switch (commandLineArgs[index])
{
case "--log-shader-sources": EngineParameters[Urho3D.EpShaderLogSources] = true; break;
case "--discard-shader-cache": EngineParameters[Urho3D.EpDiscardShaderCache] = true; break;
case "--no-save-shader-cache": EngineParameters[Urho3D.EpSaveShaderCache] = false; break;
case "--d3d11": EngineParameters[Urho3D.EpRenderBackend] = (int)RenderBackend.D3D11; break;
case "--d3d12": EngineParameters[Urho3D.EpRenderBackend] = (int)RenderBackend.D3D12; break;
case "--opengl": EngineParameters[Urho3D.EpRenderBackend] = (int)RenderBackend.OpenGl; break;
case "--vulkan": EngineParameters[Urho3D.EpRenderBackend] = (int)RenderBackend.Vulkan; break;
case "--fullscreen":
{
EngineParameters[Urho3D.EpFullScreen] = true;
EngineParameters[Urho3D.EpWindowResizable] = false;
EngineParameters[Urho3D.EpBorderless] = true;
break;
}
case "--windowed":
{
EngineParameters[Urho3D.EpFullScreen] = false;
EngineParameters[Urho3D.EpWindowResizable] = true;
EngineParameters[Urho3D.EpBorderless] = false;
break;
}
default: Log.Warning("Unknown argument " + commandLineArgs[index]); break;
}
}
}
catch (Exception e)
{
Log.Error(e.Message);
}
}


/// <summary>
/// Start application.
/// </summary>
Expand Down
19 changes: 11 additions & 8 deletions RbfxTemplate/UrhoPluginApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public class UrhoPluginApplication : PluginApplication
private static readonly FileIdentifier privacyPolicyAcceptedFileId_ =
new FileIdentifier("conf", "PrivacyPolicyAccepted");

/// <summary>
/// Settings identifier
/// </summary>
private static readonly FileIdentifier settingsFileId_ =
new FileIdentifier("conf", "Settings");

/// <summary>
/// Safe pointer to game screen.
/// </summary>
Expand All @@ -36,6 +42,11 @@ public UrhoPluginApplication(Context context) : base(context)
{
}

/// <summary>
/// Gets or sets the settings file.
/// </summary>
public GameSettings Settings { get; set; }

/// <summary>
/// Gets a value indicating whether the game is running.
/// </summary>
Expand All @@ -46,7 +57,6 @@ public override bool IsMain()
return true;
}


/// <summary>
/// Transition to game
/// </summary>
Expand Down Expand Up @@ -120,13 +130,6 @@ protected override void Start(bool isMain)
stateManager.FadeInDuration = 0.1f;
stateManager.FadeOutDuration = 0.1f;

//StringList stringList = new StringList();
//Context.VirtualFileSystem.Scan(stringList, new FileIdentifier("", "Images/Emoji"), "*.png", ScanFlag.ScanFiles);
//foreach (var imageName in stringList)
//{
// Context.ResourceCache.BackgroundLoadResource(nameof(Texture2D), "Images/Emoji/" + imageName);
//}

// Setup end enqueue splash screen.
using (SharedPtr<SplashScreen> splash = new SplashScreen(Context))
{
Expand Down

0 comments on commit 90a128c

Please sign in to comment.