Esempio n. 1
0
func Test_Level_Generate_ReturnsEntity(t *testing.T) {
	level := NewLevel()
	entity := level.Generate()

	assert.NotNil(t, entity)
	assert.NotNil(t, components.GetVisual(entity), "Did not generate a visual component")
}
Esempio n. 2
0
// TearDownEntity :: EntityListener. Cleans up any visual resources that are
// directly linked to this Entity's Visual component.
func (self *Graphical) TearDownEntity(entity *core.Entity) {
	log.Println("[Graphical] Tearing down entity", entity)

	visual := components.GetVisual(entity)
	if visual.Mesh != nil {
		self.renderer.UnloadMesh(visual.Mesh)
	}
}
Esempio n. 3
0
// SetUpEntity :: EntityListener. Will load up the mesh hooked to the given entity's
// Visual component if one was given directly instead of via MeshName
func (self *Graphical) SetUpEntity(entity *core.Entity) {
	log.Println("[Graphical] Setting up entity", entity)
	visual := components.GetVisual(entity)

	self.checkDefaultsOnVisual(visual)

	if visual.Mesh != nil {
		self.LoadMesh(visual.Mesh)
	}
}
Esempio n. 4
0
func Test_SkyBox(t *testing.T) {
	camera := core.NewCamera()
	skybox := SkyBox("testMap", camera)

	visual := components.GetVisual(skybox)
	transform := components.GetTransform(skybox)

	assert.Equal(t, "Skybox testMap", skybox.Name)
	assert.Equal(t, "testMap", visual.MaterialName)
	assert.Equal(t, camera.Entity, transform.UsingPositionOf)
}
func Test_ComponentAdded_HandlesComponentReplacementProperly(t *testing.T) {
	db, listeners := RegisterDBAndListeners()
	entity := NewEntity()
	oldVisual := new(components.Visual)
	entity.AddComponent(oldVisual)
	db.RegisterEntity(entity)

	// Now replace the oldVisual with a new visual component
	entity.RemoveComponent(components.VISUAL)
	newVisual := new(components.Visual)
	entity.AddComponent(newVisual)

	assert.Equal(t, entity, listeners[1].tearDownEntities[0])
	assert.Equal(t, entity, listeners[1].setUpEntities[0])

	// Entity still stored
	assert.True(t, listeners[1].entitySet.Contains(entity))
	// Using the new visual component (move test elsewhere?)
	assert.Equal(t, newVisual, components.GetVisual(entity))
}
Esempio n. 6
0
// Update is called every Game tick
func (self *Graphical) Update(camera *core.Camera, deltaT float32) {
	self.renderer.BeginRender()
	var visual *components.Visual

	renderQueue := render.NewRenderQueue()

	renderQueue.ProjectionMatrix = camera.ProjectionMatrix()
	renderQueue.ViewMatrix = camera.ViewMatrix()

	for _, entity := range self.entitySet.Entities() {
		visual = components.GetVisual(entity)

		renderQueue.Add(render.RenderOperation{
			Mesh:      self.meshFromVisual(visual),
			Material:  self.materialLoader.Get(visual.MaterialName),
			Transform: components.GetTransform(entity).TransformMatrix(),
		})
	}

	self.renderer.Render(renderQueue)

	self.renderer.FinishRender()
}
Esempio n. 7
0
func Test_Player_HasEntity(t *testing.T) {
	player := NewPlayer()

	assert.NotNil(t, player)
	assert.NotNil(t, components.GetVisual(player.GetEntity()), "Did not generate a visual component")
}