Harbor

branch main
showing the latest snapshot on main
particles_test.odin 1.7 KB · Plain text
tests/particles_test.odin 0644 Raw
package gpu_tests

import gpu ".."
import particles "../particles"
import "core:testing"

@(test)
test_particles_producer_auto_emit_and_frame_packets :: proc(t: ^testing.T) {
	config := particles.Config {
		max_particles = 4,
		emission_rate = 100,
		lifetime      = {1, 1},
		speed         = {0, 0},
		direction     = {0, -1},
		spread        = 0,
		start_color   = {1, 0, 0, 1},
		end_color     = {1, 0, 0, 1},
		start_size    = 10,
		end_size      = 10,
		gravity       = {0, 0},
	}
	system, ok := particles.init(config, seed = 1)
	testing.expect(t, ok)
	defer particles.destroy(&system)

	particles.update(&system, {10, 20}, 0.02)
	testing.expect_value(t, particles.alive_count(&system), u32(2))

	ctx := gpu.init_context(width = 640, height = 480)
	frame := gpu.begin_frame(ctx)
	defer gpu.destroy_frame(&frame)
	_ = gpu.begin_target(&frame, gpu.present_target(ctx))
	_ = gpu.push_layer(&frame, {name = "particles", order = .Sortable})

	particles.draw_2d(&frame, &system)

	plan := gpu.frame_runtime_plan(&frame)
	defer gpu.destroy_frame_runtime_plan(&plan)
	testing.expect_value(t, len(plan), 2)

	mode, mode_ok := gpu.frame_runtime_mode(&frame)
	testing.expect(t, mode_ok)
	testing.expect(t, mode == .Generated_2D)
	testing.expect(t, gpu.submit(&frame))
}

@(test)
test_particles_producer_burst_caps_at_capacity :: proc(t: ^testing.T) {
	config := particles.default_config()
	config.max_particles = 3
	config.emission_rate = 0
	config.lifetime = {1, 1}
	config.speed = {0, 0}

	system, ok := particles.init(config, seed = 1)
	testing.expect(t, ok)
	defer particles.destroy(&system)

	particles.emit(&system, {0, 0}, 10)
	testing.expect_value(t, particles.alive_count(&system), u32(3))
}