summaryrefslogtreecommitdiff
path: root/game/vehicles/railVehicleClass.h
blob: b7f6c5923e1545f7fdfa55d5f41ebff25b5c69ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#pragma once

#include "assetFactory/asset.h"
#include "assetFactory/lights.h"
#include "gfx/gl/instanceVertices.h"
#include "gfx/models/mesh.h"
#include "gfx/models/texture.h"
#include "gfx/renderable.h"
#include <array>
#include <memory>

class SceneShader;
class ShadowMapper;
class Location;

class RailVehicleClass : public Renderable, public Asset {
public:
	void render(const SceneShader & shader, const Frustum &) const override;
	void shadows(const ShadowMapper & shadowMapper, const Frustum &) const override;

	[[nodiscard]] std::any createAt(const Location &) const override;

	struct InstanceVertex {
		CommonLocationInstance body, front, back;
	};

	std::array<Mesh::Ptr, 2> bogies;
	Mesh::Ptr bodyMesh;
	Texture::Ptr texture;
	std::vector<SpotLight::Ptr> spotLight;
	std::vector<PointLight::Ptr> pointLight;
	float wheelBase;
	float length;
	float maxSpeed;

	mutable InstanceVertices<InstanceVertex> instances;
	using Instance = decltype(instances)::InstanceProxy;

protected:
	friend Persistence::SelectionPtrBase<std::shared_ptr<RailVehicleClass>>;
	bool persist(Persistence::PersistenceStore & store) override;
	void postLoad() override;
	void renderAllParts(size_t count) const;

private:
	glVertexArray instanceVAO;
};

using RailVehicleClassPtr = std::shared_ptr<RailVehicleClass>;