Skip to content

Commit

Permalink
Slight code re-org.
Browse files Browse the repository at this point in the history
Updated Prime.


Former-commit-id: ba0bda0
  • Loading branch information
bryanedds committed Mar 15, 2016
1 parent 6604106 commit cd56434
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 48 deletions.
1 change: 0 additions & 1 deletion Nu/Nu/Nu/Nu.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
<Compile Include="WorldGroup.fs" />
<Compile Include="WorldScreen.fs" />
<Compile Include="WorldGame.fs" />
<Compile Include="WorldSimulant.fs" />
<Compile Include="WorldInput.fs" />
<Compile Include="WorldClipboard.fs" />
<Compile Include="WorldPhysics.fs" />
Expand Down
14 changes: 7 additions & 7 deletions Nu/Nu/Nu/WorldDispatchers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ module GuiDispatcherModule =
let gui = evt.Subscriber : Entity
let data = evt.Data : MouseButtonData
let handling =
if World.isSimulantSelected gui world && gui.GetVisible world then
if World.isEntitySelected gui world && gui.GetVisible world then
let mousePositionWorld = World.getCameraBy (Camera.mouseToWorld (gui.GetViewType world) data.Position) world
if data.Down &&
gui.GetSwallowMouseLeft world &&
Expand Down Expand Up @@ -407,7 +407,7 @@ module ButtonDispatcherModule =
let handleMouseLeftDown evt world =
let button = evt.Subscriber : Entity
let data = evt.Data : MouseButtonData
if World.isSimulantSelected button world then
if World.isEntitySelected button world then
let mousePositionWorld = World.getCameraBy (Camera.mouseToWorld (button.GetViewType world) data.Position) world
if button.GetVisible world &&
Math.isPointInBounds mousePositionWorld (button.GetBounds world) then
Expand All @@ -423,7 +423,7 @@ module ButtonDispatcherModule =
let handleMouseLeftUp evt world =
let button = evt.Subscriber : Entity
let data = evt.Data : MouseButtonData
if World.isSimulantSelected button world then
if World.isEntitySelected button world then
let wasDown = button.GetDown world
let world = button.SetDown false world
let mousePositionWorld = World.getCameraBy (Camera.mouseToWorld (button.GetViewType world) data.Position) world
Expand Down Expand Up @@ -595,7 +595,7 @@ module ToggleDispatcherModule =
let handleMouseLeftDown evt world =
let toggle = evt.Subscriber : Entity
let data = evt.Data : MouseButtonData
if World.isSimulantSelected toggle world then
if World.isEntitySelected toggle world then
let mousePositionWorld = World.getCameraBy (Camera.mouseToWorld (toggle.GetViewType world) data.Position) world
if toggle.GetVisible world &&
Math.isPointInBounds mousePositionWorld (toggle.GetBounds world) then
Expand All @@ -609,7 +609,7 @@ module ToggleDispatcherModule =
let handleMouseLeftUp evt world =
let toggle = evt.Subscriber : Entity
let data = evt.Data : MouseButtonData
if World.isSimulantSelected toggle world then
if World.isEntitySelected toggle world then
let wasPressed = toggle.GetPressed world
let world = toggle.SetPressed false world
let mousePositionWorld = World.getCameraBy (Camera.mouseToWorld (toggle.GetViewType world) data.Position) world
Expand Down Expand Up @@ -678,7 +678,7 @@ module FeelerDispatcherModule =
let handleMouseLeftDown evt world =
let feeler = evt.Subscriber : Entity
let data = evt.Data : MouseButtonData
if World.isSimulantSelected feeler world then
if World.isEntitySelected feeler world then
let mousePositionWorld = World.getCameraBy (Camera.mouseToWorld (feeler.GetViewType world) data.Position) world
if feeler.GetVisible world &&
Math.isPointInBounds mousePositionWorld (feeler.GetBounds world) then
Expand All @@ -694,7 +694,7 @@ module FeelerDispatcherModule =
let handleMouseLeftUp evt world =
let feeler = evt.Subscriber : Entity
let data = evt.Data : MouseButtonData
if World.isSimulantSelected feeler world && feeler.GetVisible world then
if World.isEntitySelected feeler world && feeler.GetVisible world then
if feeler.GetEnabled world then
let world = feeler.SetTouched false world
let eventTrace = EventTrace.record "FeelerDispatcher" "handleMouseLeftDown" EventTrace.empty
Expand Down
14 changes: 5 additions & 9 deletions Nu/Nu/Nu/WorldEvents.fs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ type [<StructuralEquality; NoComparison>] KeyboardKeyData =
Repeated : bool
Down : bool }

/// The data for a change in a simulant.
type SimulantChangeData<'s, 'w when 's :> Simulant and 'w :> 'w Eventable> =
ParticipantChangeData<'s, 'w>

/// The data for a collision event.
type [<StructuralEquality; NoComparison>] CollisionData =
{ Normal : Vector2
Expand All @@ -35,7 +31,7 @@ type [<StructuralEquality; NoComparison>] CollisionData =

/// The data for a change in the world's ambient state.
/// NOTE: I couldn't give its field the more normal name of 'OldWorld' due to field name conflicts with the more
/// pervasive SimulantChangeData type below.
/// pervasive ParticipantChangeData type.
type [<StructuralEquality; NoComparison>] AmbientStateChangeData =
{ OldWorldWithOldState : World }

Expand Down Expand Up @@ -90,16 +86,16 @@ module Events =
let AmbientState = ntoa<obj> !!"AmbientState"
let AmbientStateChange = AmbientState -<- ntoa<AmbientStateChangeData> !!"Change"
let Game = ntoa<obj> !!"Game"
let GameChange = Game -<- ntoa<SimulantChangeData<Game, World>> !!"Change"
let GameChange = Game -<- ntoa<ParticipantChangeData<Game, World>> !!"Change"
let Screen = ntoa<obj> !!"Screen"
let ScreenAdd = Screen -<- ntoa<unit> !!"Add"
let ScreenRemoving = Screen -<- ntoa<unit> !!"Removing"
let ScreenChange = Screen -<- ntoa<SimulantChangeData<Screen, World>> !!"Change"
let ScreenChange = Screen -<- ntoa<ParticipantChangeData<Screen, World>> !!"Change"
let Group = ntoa<obj> !!"Group"
let GroupAdd = Group -<- ntoa<unit> !!"Add"
let GroupRemoving = Group -<- ntoa<unit> !!"Removing"
let GroupChange = Group -<- ntoa<SimulantChangeData<Group, World>> !!"Change"
let GroupChange = Group -<- ntoa<ParticipantChangeData<Group, World>> !!"Change"
let Entity = ntoa<obj> !!"Entity"
let EntityAdd = Entity -<- ntoa<unit> !!"Add"
let EntityRemoving = Entity -<- ntoa<unit> !!"Removing"
let EntityChange = Entity -<- ntoa<SimulantChangeData<Entity, World>> !!"Change"
let EntityChange = Entity -<- ntoa<ParticipantChangeData<Entity, World>> !!"Change"
28 changes: 28 additions & 0 deletions Nu/Nu/Nu/WorldGame.fs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,34 @@ module WorldGameModule =
static member setSelectedScreen screen world =
World.setOptSelectedScreen (Some screen) world

/// Determine if an entity is selected by being in a group of the currently selected screeen.
static member isEntitySelected entity world =
let screenName = Address.head entity.EntityAddress
match World.getOptSelectedScreen world with
| Some selectedScreen -> screenName = selectedScreen.ScreenName
| None -> false

/// Determine if a group is selected by being in the currently selected screeen.
static member isGroupSelected group world =
let screenName = Address.head group.GroupAddress
match World.getOptSelectedScreen world with
| Some selectedScreen -> screenName = selectedScreen.ScreenName
| None -> false

/// Determine if a screen is the currently selected screeen.
static member isScreenSelected screen world =
World.getOptSelectedScreen world = Some screen

/// Determine if a simulant is contained by, or is the same as, the currently selected screen.
/// Game is always considered 'selected' as well.
static member isSimulantSelected (simulant : Simulant) world =
match Address.getNames simulant.SimulantAddress with
| [] -> true
| screenName :: _ ->
match World.getOptSelectedScreen world with
| Some screen -> screen.ScreenName = screenName
| None -> false

/// Write a game to an xml writer.
static member writeGame (writer : XmlWriter) world =
let gameState = World.getGameState world
Expand Down
10 changes: 6 additions & 4 deletions Nu/Nu/Nu/WorldObservation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ module Observation =
observation |> organize (fun _ world -> World.getUpdateCount world) |> toFst |> choose

/// Take events from an observation only while World.isTicking evaluates to true.
let [<DebuggerHidden; DebuggerStepThrough>] isTicking _ world = World.isTicking world
let [<DebuggerHidden; DebuggerStepThrough>] isTicking _ world =
World.isTicking world

/// Take events from an observation only when the observer is selected in the world (see
/// documentation for World.isAddressSelected for what this means (it's very useful!)).
let [<DebuggerHidden; DebuggerStepThrough>] isObserverSelected evt world = World.isSimulantSelected evt.Subscriber world
/// Take events from an observation only when the observer is contained by, or is the same as,
/// the currently selected screen. Game is always considered 'selected' as well.
let [<DebuggerHidden; DebuggerStepThrough>] isObserverSelected evt world =
World.isSimulantSelected evt.Subscriber world

/// Take events from an observation only when the currently selected screen is idling (that
/// is, there is no screen transition in progress).
Expand Down
27 changes: 0 additions & 27 deletions Nu/Nu/Nu/WorldSimulant.fs

This file was deleted.

Binary file modified Nu/Prime/Debug/Prime.exe
Binary file not shown.
Binary file modified Nu/Prime/Debug/Prime.pdb
Binary file not shown.
Binary file modified Nu/Prime/Release/Prime.exe
Binary file not shown.
Binary file modified Nu/Prime/Release/Prime.pdb
Binary file not shown.

0 comments on commit cd56434

Please sign in to comment.