<commit_before>// Copyright 2014 <NAME>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package engi

import "math"

// A rather basic camera
type Camera struct {
	pos, to  Point
	tracking *Entity // The entity that is currently being followed
}

func (cam *Camera) FollowEntity(entity *Entity) {
	cam.tracking = entity
	var space *SpaceComponent
	if !cam.tracking.GetComponent(&space) {
		return
	}

	cam.to = space.Position
	cam.centerCam(Width(), Height(), 1, space)
}

func (cam *Camera) Update(dt float32) {
	// maxPoints := 8
	if cam.tracking != nil {
		var space *SpaceComponent
		if !cam.tracking.GetComponent(&space) {
			return
		}
		cam.centerCam(Width(), Height(), 0.09, space)
	}
}

func (cam *Camera) centerCam(width, height, lerp float32, space *SpaceComponent) {
	cam.to.X += ((space.Position.X + space.Width/2) - (cam.to.X + width/2)) * lerp
	cam.to.Y += ((space.Position.Y + space.Height/2) - (cam.to.Y + height/2)) * lerp

	cam.pos.X = Clamp(floorFloat32(cam.to.X), 0, WorldBounds.Max.X-width)
	cam.pos.Y = Clamp(floorFloat32(cam.to.Y), 0, WorldBounds.Max.Y-height)
}

func floorFloat32(i float32) float32 {
	return float32(math.Floor(float64(i)))
}<commit_msg>camera: add basic deadzone<commit_after>// Copyright 2014 <NAME>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package engi

import "math"

// A rather basic camera
type Camera struct {
	pos, to  Point
	tracking *Entity // The entity that is currently being followed
}

func (cam *Camera) FollowEntity(entity *Entity) {
	cam.tracking = entity
	var space *SpaceComponent
	if !cam.tracking.GetComponent(&space) {
		return
	}

	cam.to = space.Position
	cam.centerCam(Width(), Height(), 1, space)
}

func (cam *Camera) Update(dt float32) {
	// maxPoints := 8
	if cam.tracking != nil {
		var space *SpaceComponent
		if !cam.tracking.GetComponent(&space) {
			return
		}
		cam.centerCam(Width(), Height(), 0.09, space)
	}
}

func (cam *Camera) centerCam(width, height, lerp float32, space *SpaceComponent) {
	cam.to.X += ((space.Position.X + space.Width/2) - (cam.to.X + width/2)) * lerp
	cam.to.Y += ((space.Position.Y + space.Height/2) - (cam.to.Y + height/2)) * lerp

	posX := cam.to.X
	posY := cam.to.Y

	minX, minY := posX-100, posY-100
	maxX, maxY := minX+200, minY+200

	if cam.pos.X < minX {
		cam.pos.X = Clamp(floorFloat32(minX), 0, WorldBounds.Max.X-width)
	}

	if cam.pos.X > maxX {
		cam.pos.X = Clamp(floorFloat32(maxX), 0, WorldBounds.Max.X-width)
	}

	if posY < minY {
		cam.pos.Y = Clamp(floorFloat32(minY), 0, WorldBounds.Max.Y-height)
	}

	if posY > maxY {
		cam.pos.Y = Clamp(floorFloat32(maxY), 0, WorldBounds.Max.Y-height)
	}

}

func floorFloat32(i float32) float32 {
	return float32(math.Floor(float64(i)))
}
{'fraction_non_alphanumeric': 0.14898813677599443, 'fraction_numerical': 0.02930914166085136, 'mean_word_length': 3.6693811074918568, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4835240', 'n_tokens_mistral': 1146, 'n_tokens_neox': 1047, 'n_words': 281}