MCPcopy
hub / github.com/EngoEngine/engo / Update

Method Update

common/mouse.go:184–318  ·  view source on GitHub ↗

Update updates all the entities in the MouseSystem.

(dt float32)

Source from the content-addressed store, hash-verified

182
183// Update updates all the entities in the MouseSystem.
184func (m *MouseSystem) Update(dt float32) {
185 // Translate Mouse.X and Mouse.Y into "game coordinates"
186 switch engo.CurrentBackEnd {
187 case engo.BackEndGLFW, engo.BackEndSDL, engo.BackEndVulkan:
188 m.mouseX = ((engo.Input.Mouse.X * m.camera.Z() * engo.GameWidth() / engo.WindowWidth()) + (m.camera.X()-(engo.GameWidth()/2)*m.camera.Z())/engo.GetGlobalScale().X)
189 m.mouseY = ((engo.Input.Mouse.Y * m.camera.Z() * engo.GameHeight() / engo.WindowHeight()) + (m.camera.Y()-(engo.GameHeight()/2)*m.camera.Z())/engo.GetGlobalScale().Y)
190 case engo.BackEndMobile, engo.BackEndWeb:
191 m.mouseX = engo.Input.Mouse.X*m.camera.Z() + (m.camera.X()-(engo.GameWidth()/2)*m.camera.Z()+(engo.ResizeXOffset/2))/engo.GetGlobalScale().X
192 m.mouseY = engo.Input.Mouse.Y*m.camera.Z() + (m.camera.Y()-(engo.GameHeight()/2)*m.camera.Z()+(engo.ResizeYOffset/2))/engo.GetGlobalScale().Y
193 }
194
195 // Rotate if needed
196 if m.camera.angle != 0 {
197 sin, cos := math.Sincos(m.camera.angle * math.Pi / 180)
198 m.mouseX, m.mouseY = m.mouseX*cos+m.mouseY*sin, m.mouseY*cos-m.mouseX*sin
199 }
200
201 for _, e := range m.entities {
202 // Reset all values except these
203 *e.MouseComponent = MouseComponent{
204 Track: e.MouseComponent.Track,
205 Hovered: e.MouseComponent.Hovered,
206 startedDragging: e.MouseComponent.startedDragging,
207 startedMoving: e.MouseComponent.startedMoving,
208 rightStartedDragging: e.MouseComponent.rightStartedDragging,
209 rightStartedMoving: e.MouseComponent.rightStartedMoving,
210 }
211
212 if e.MouseComponent.Track {
213 // track mouse position so that systems that need to stay on the mouse
214 // position can do it (think an RTS when placing a new building and
215 // you get a ghost building following your mouse until you click to
216 // place it somewhere in your world.
217 e.MouseComponent.MouseX = m.mouseX
218 e.MouseComponent.MouseY = m.mouseY
219 }
220
221 mx := m.mouseX
222 my := m.mouseY
223
224 if e.SpaceComponent == nil {
225 continue // with other entities
226 }
227
228 if e.RenderComponent != nil {
229 // Hardcoded special case for the HUD | TODO: make generic instead of hardcoding
230 if e.RenderComponent.shader == HUDShader || e.RenderComponent.shader == LegacyHUDShader {
231 mx = engo.Input.Mouse.X
232 my = engo.Input.Mouse.Y
233 }
234
235 if e.RenderComponent.Hidden {
236 continue // skip hidden components
237 }
238 }
239
240 // If the Mouse component is a tracker we always update it
241 // Check if the X-value is within range

Callers

nothing calls this directly

Calls 10

GameWidthFunction · 0.92
WindowWidthFunction · 0.92
GetGlobalScaleFunction · 0.92
GameHeightFunction · 0.92
WindowHeightFunction · 0.92
SincosFunction · 0.92
ZMethod · 0.80
XMethod · 0.80
YMethod · 0.80
ContainsMethod · 0.65

Tested by

no test coverage detected