Skip to content

Commit

Permalink
[3D] Support 3D.
Browse files Browse the repository at this point in the history
  • Loading branch information
riperiperi committed Sep 1, 2017
1 parent e719817 commit 1dad877
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 32 deletions.
3 changes: 2 additions & 1 deletion Client/Simitone/Simitone.Client/SimitoneGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ protected override void Initialize()
{
AdvancedLighting = settings.Lighting,
SmoothZoom = settings.SmoothZoom,
SurroundingLots = settings.SurroundingLotMode
SurroundingLots = settings.SurroundingLotMode,
AA = settings.AntiAlias
};

OperatingSystem os = Environment.OSVersion;
Expand Down
51 changes: 31 additions & 20 deletions Client/Simitone/Simitone.Client/UI/Panels/UILotControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
using FSO.Content;
using FSO.Client.Debug;
using Simitone.Client.UI.Screens;
using FSO.LotView.RC;

namespace Simitone.Client.UI.Panels
{
Expand Down Expand Up @@ -593,24 +594,34 @@ public override void Update(UpdateState state)
if (!vm.Ready || vm.Context.Architecture == null) return;

//handling smooth scaled zoom
float BaseScale;
WorldZoom targetZoom;
if (TargetZoom < 0.5f)
if (FSOEnvironment.Enable3D)
{
targetZoom = WorldZoom.Far;
BaseScale = 0.25f;
} else if (TargetZoom < 1f)
{
targetZoom = WorldZoom.Medium;
BaseScale = 0.5f;
} else
var s3d = ((WorldStateRC)World.State);
s3d.Zoom3D += ((9.75f - (TargetZoom-0.25f)*10) - s3d.Zoom3D) / 10;
}
else
{
targetZoom = WorldZoom.Near;
BaseScale = 1f;
float BaseScale;
WorldZoom targetZoom;
if (TargetZoom < 0.5f)
{
targetZoom = WorldZoom.Far;
BaseScale = 0.25f;
}
else if (TargetZoom < 1f)
{
targetZoom = WorldZoom.Medium;
BaseScale = 0.5f;
}
else
{
targetZoom = WorldZoom.Near;
BaseScale = 1f;
}
World.BackbufferScale = TargetZoom / BaseScale;
if (World.State.Zoom != targetZoom) World.State.Zoom = targetZoom;
WorldConfig.Current.SmoothZoom = false;
}
World.BackbufferScale = TargetZoom/BaseScale;
if (World.State.Zoom != targetZoom) World.State.Zoom = targetZoom;
WorldConfig.Current.SmoothZoom = false;

//Cheats.Update(state);
//AvatarDS.Update();
Expand Down Expand Up @@ -770,21 +781,21 @@ private void UpdateCutaway(UpdateState state)
if (RMBScroll || !MouseIsOn) return;
finalRooms = new HashSet<uint>(CutRooms);
var newCut = new Rectangle((int)(mouseTilePos.X - 2.5), (int)(mouseTilePos.Y - 2.5), 5, 5);
newCut.X -= VMArchitectureTools.CutCheckDir[(int)World.State.Rotation][0] * 2;
newCut.Y -= VMArchitectureTools.CutCheckDir[(int)World.State.Rotation][1] * 2;
newCut.X -= VMArchitectureTools.CutCheckDir[(int)World.State.CutRotation][0] * 2;
newCut.Y -= VMArchitectureTools.CutCheckDir[(int)World.State.CutRotation][1] * 2;
if (newCut != MouseCutRect)
{
MouseCutRect = newCut;
recut = 1;
}
}

if (LastFloor != World.State.Level || LastRotation != World.State.Rotation || !finalRooms.SetEquals(LastCutRooms))
if (LastFloor != World.State.Level || LastRotation != World.State.CutRotation || !finalRooms.SetEquals(LastCutRooms))
{
LastCuts = VMArchitectureTools.GenerateRoomCut(vm.Context.Architecture, World.State.Level, World.State.Rotation, finalRooms);
LastCuts = VMArchitectureTools.GenerateRoomCut(vm.Context.Architecture, World.State.Level, World.State.CutRotation, finalRooms);
recut = 2;
LastFloor = World.State.Level;
LastRotation = World.State.Rotation;
LastRotation = World.State.CutRotation;
}
LastCutRooms = finalRooms;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using FSO.HIT;
using FSO.Client.UI.Model;
using Simitone.Client.UI.Screens;
using FSO.LotView.RC;
using FSO.Common.Utils;

namespace Simitone.Client.UI.Panels
{
Expand All @@ -32,6 +34,8 @@ public class UILotControlTouchHelper : UIElement
private Vector2 BaseVector;
private float StartScale;
private float RotateAngle;
//for 3D rotate
private float? LastAngleX;

private UIRotationAnimation RotationAnim;

Expand All @@ -52,6 +56,7 @@ public UILotControlTouchHelper(UILotControl master)
private int ZoomFreezeTime;
public override void Update(UpdateState state)
{
var _3d = FSOEnvironment.Enable3D;
base.Update(state);
bool rotated = false;

Expand All @@ -66,7 +71,7 @@ public override void Update(UpdateState state)
if (state.WindowFocused && state.MouseState.ScrollWheelValue != LastMouseWheel)
{
var diff = state.MouseState.ScrollWheelValue - LastMouseWheel;
Master.TargetZoom = Master.TargetZoom + diff / 1000f;
Master.TargetZoom = Master.TargetZoom + diff / 1600f;
LastMouseWheel = state.MouseState.ScrollWheelValue;
Master.TargetZoom = Math.Max(0.25f, Math.Min(Master.TargetZoom, 2));
ZoomFreezeTime = 10;
Expand Down Expand Up @@ -113,6 +118,7 @@ public override void Update(UpdateState state)
var m2 = state.MouseStates.FirstOrDefault(x => x.ID == MiceDown.ElementAt(1));
BaseVector = (new Point(m2.MouseState.X, m2.MouseState.Y) - new Point(m1.MouseState.X, m1.MouseState.Y)).ToVector2();
StartScale = Master.TargetZoom;
if (_3d) LastAngleX = null;

//scroll anchor should change to center of two touches without drastically changing scroll
TapPoint = (new Point(m2.MouseState.X / 2, m2.MouseState.Y / 2) + new Point(m1.MouseState.X / 2, m1.MouseState.Y / 2));
Expand All @@ -124,8 +130,14 @@ public override void Update(UpdateState state)
if (Mode == 0)
{
ScrollVelocity = new Vector2();
if (transitionTo == -1) Mode = -1;
else {
if (transitionTo == -1)
{
Mode = -1;
var screenMiddle = new Point(GameFacade.Screens.CurrentUIScreen.ScreenWidth / 2, GameFacade.Screens.CurrentUIScreen.ScreenHeight / 2);
Master.ShowPieMenu(((TapPoint - screenMiddle).ToVector2() / Master.World.BackbufferScale).ToPoint() + screenMiddle, state);
}
else
{
var mouse = state.MouseStates.FirstOrDefault(x => x.ID == MiceDown.First());
if ((TapPoint - new Point(mouse.MouseState.X, mouse.MouseState.Y)).ToVector2().Length() > TAP_POINT_DIST)
{
Expand Down Expand Up @@ -185,18 +197,24 @@ public override void Update(UpdateState state)
var a = BaseVector;
var b = vector;
a.Normalize(); b.Normalize();
var clockwise = ((-a.Y)*b.X + a.X*b.Y) > 0;
var clockwise = ((-a.Y) * b.X + a.X * b.Y) > 0;
var angle = (float)Math.Acos(Vector2.Dot(a, b));
RotateAngle = (clockwise) ? angle : -angle;

if (Math.Abs(RotateAngle) > Math.PI / 8) Master.TargetZoom = StartScale;
if (_3d)
{
if (LastAngleX != null) ((WorldStateRC)Master.World.State).RotationX -= (float)DirectionUtils.Difference(RotateAngle, LastAngleX.Value);
LastAngleX = RotateAngle;
} else {
if (Math.Abs(RotateAngle) > Math.PI / 8) Master.TargetZoom = StartScale;
}
}
break;
case 3:
if (transitionTo == -1) Mode = -1;
break;
}
if (Mode != 2 && RotateAngle != 0)
if (Mode != 2 && RotateAngle != 0 && !_3d)
{
if (Math.Abs(RotateAngle) > Math.PI / 4)
{
Expand Down Expand Up @@ -237,7 +255,7 @@ public override void Update(UpdateState state)
if (Mode == -1)
{
ScrollVelocity *= 0.95f * Math.Min(ScrollVelocity.Length(), 1);
if (Master.TargetZoom < 1.25f && ZoomFreezeTime == 0) {
if (Master.TargetZoom < 1.25f && ZoomFreezeTime == 0 && !_3d) {
float snapZoom = 1f;
float dist = 200f;
foreach (var snappable in SnapZooms)
Expand Down Expand Up @@ -265,7 +283,7 @@ public override void Update(UpdateState state)

UpdatesSinceDraw++;

if (Math.Abs(RotateAngle) > Math.PI / 8) //>20 degrees starts a rotation gesture. 40 degrees ends it.
if (Math.Abs(RotateAngle) > Math.PI / 8 && !_3d) //>20 degrees starts a rotation gesture. 40 degrees ends it.
{
if (RotationAnim == null)
{
Expand Down
7 changes: 7 additions & 0 deletions Client/Simitone/Simitone.Client/UI/Panels/UIMainPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,5 +284,12 @@ public void ShowSelect()
ShowingSelect = false;
};
}

public override void GameResized()
{
base.GameResized();
if (PanelActive) CurWidth = Game.ScreenWidth - (64 + 15);
HideButton.X = Game.ScreenWidth - (50 + 64 + 15);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public UISimitoneFrontend(TS1GameScreen screen)
btn.OnButtonClick += LiveButtonClicked;
Add(btn);
LiveButton = btn;

ExtendPanelBtn.Position = new Vector2(btn.X + 54, btn.Y - 50);

MainPanel.X = 64 + 15;
Expand Down Expand Up @@ -153,6 +153,12 @@ public override void GameResized()
if (CutPanel != null) CutPanel.X = CutBtn.X - 39;
Clock.X = Game.ScreenWidth - (334 + 15);
Clock.Y = 15;

Money.Position = new Vector2(15, Game.ScreenHeight - 172);
var btn = LiveButton;
btn.Position = new Vector2(64 + 15, Game.ScreenHeight - (64 + 15));
ExtendPanelBtn.Position = new Vector2(btn.X + 54, btn.Y - 50);
MainPanel.Y = btn.Y - 64;
}
}
}
12 changes: 11 additions & 1 deletion Client/Simitone/Simitone.Client/UI/Screens/TS1GameScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ public override void Update(FSO.Common.Rendering.Framework.Model.UpdateState sta
{
GameFacade.Game.IsFixedTimeStep = (vm == null || vm.Ready);

Visible = (World?.State as FSO.LotView.RC.WorldStateRC)?.CameraMode != true;
GameFacade.Game.IsMouseVisible = Visible;

base.Update(state);
if (state.NewKeys.Contains(Keys.NumPad1)) ChangeSpeedTo(1);
if (state.NewKeys.Contains(Keys.NumPad2)) ChangeSpeedTo(2);
Expand Down Expand Up @@ -345,7 +348,14 @@ public void InitializeLot()
{
CleanupLastWorld();

World = new FSO.LotView.World(GameFacade.GraphicsDevice);
if (FSOEnvironment.Enable3D)
{
World = new FSO.LotView.RC.WorldRC(GameFacade.GraphicsDevice);
} else
{
World = new FSO.LotView.World(GameFacade.GraphicsDevice);
}

World.Opacity = 1;
GameFacade.Scenes.Add(World);

Expand Down
4 changes: 4 additions & 0 deletions Client/Simitone/Simitone.Windows/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ static void Main(string[] args)
case "ide":
ide = true;
break;
case "3d":
FSOEnvironment.Enable3D = true;
break;
}
}
}
Expand All @@ -72,6 +75,7 @@ static void Main(string[] args)
GlobalSettings.Default.TS1HybridEnable = true;
GlobalSettings.Default.TS1HybridPath = gameLocator.FindTheSims1();
GlobalSettings.Default.ClientVersion = "0";
GlobalSettings.Default.AntiAlias = true;

GameFacade.DirectX = useDX;
World.DirectX = useDX;
Expand Down
2 changes: 1 addition & 1 deletion FreeSO
Submodule FreeSO updated 216 files

0 comments on commit 1dad877

Please sign in to comment.