<commit_before>#include <improbable/standard_library.h>
#include <improbable/worker.h>
#include <shoveler.h>

extern "C" {
#include <shoveler/camera/perspective.h>
#include <shoveler/light/point.h>
#include <shoveler/constants.h>
#include <shoveler/game.h>
#include <shoveler/log.h>
#include <shoveler/types.h>

#include "worker_view.h"
}

using shoveler::Drawable;
using shoveler::DrawableType;
using shoveler::Material;
using shoveler::MaterialType;
using shoveler::Model;
using improbable::Coordinates;
using improbable::Position;

static void updateGame(ShovelerGame *game, double dt);
static ShovelerSpatialOsWorkerViewDrawableConfiguration createDrawableConfiguration(const Drawable& drawable);
static ShovelerSpatialOsWorkerViewMaterialConfiguration createMaterialConfiguration(const Material& material);

int main(int argc, char **argv) {
	if (argc != 4) {
		return 1;
	}

	const char *windowTitle = "ShovelerClient";
	bool fullscreen = false;
	bool vsync = true;
	int samples = 4;
	int width = 640;
	int height = 480;

	ShovelerGame *game = shovelerGameCreate(windowTitle, width, height, samples, fullscreen, vsync);
	if(game == NULL) {
		return EXIT_FAILURE;
	}

	worker::ConnectionParameters parameters;
	parameters.WorkerType = "ShovelerClient";
	parameters.Network.ConnectionType = worker::NetworkConnectionType::kTcp;
	parameters.Network.UseExternalIp = false;

	const std::string workerId = argv[1];
	const std::string hostname = argv[2];
	const std::uint16_t port = static_cast<std::uint16_t>(std::stoi(argv[3]));

	shovelerLogInfo("Connecting as worker %s to %s:%d.", workerId.c_str(), hostname.c_str(), port);
	worker::Connection connection = worker::Connection::ConnectAsync(hostname, port, workerId, parameters).Get();
	bool disconnected = false;
	worker::Dispatcher dispatcher;

	game->camera = shovelerCameraPerspectiveCreate(ShovelerVector3{0.0, 0.0, -1.0}, ShovelerVector3{0.0, 0.0, 1.0}, ShovelerVector3{0.0, 1.0, 0.0}, 2.0f * SHOVELER_PI * 50.0f / 360.0f, (float) width / height, 0.01, 1000);
	game->scene = shovelerSceneCreate();
	game->update = updateGame;
	ShovelerSpatialOsWorkerView *view = shovelerSpatialOsWorkerViewCreate(game->scene);

	dispatcher.OnDisconnect([&](const worker::DisconnectOp& op) {
		shovelerLogError("Disconnected from SpatialOS: %s", op.Reason.c_str());
		disconnected = true;
	});

	dispatcher.OnAddEntity([&](const worker::AddEntityOp& op) {
		shovelerLogInfo("Adding entity %lld.", op.EntityId);
		shovelerSpatialOsWorkerViewAddEntity(view, op.EntityId);
	});

	dispatcher.OnRemoveEntity([&](const worker::RemoveEntityOp& op) {
		shovelerLogInfo("Removing entity %lld.", op.EntityId);
		shovelerSpatialOsWorkerViewRemoveEntity(view, op.EntityId);
	});

	dispatcher.OnAddComponent<Position>([&](const worker::AddComponentOp<Position>& op) {
		shovelerLogInfo("Adding position to entity %lld.", op.EntityId);
		ShovelerVector3 position{(float) op.Data.coords().x(), (float) op.Data.coords().y(), (float) op.Data.coords().z()};
		shovelerSpatialOsWorkerViewAddEntityPosition(view, op.EntityId, position);
	});

	dispatcher.OnComponentUpdate<Position>([&](const worker::ComponentUpdateOp<Position>& op) {
		shovelerLogInfo("Updating position for entity %lld.", op.EntityId);
		if(op.Update.coords()) {
			const Coordinates& coordinates = *op.Update.coords();
			ShovelerVector3 position{(float) coordinates.x(), (float) coordinates.y(), (float) coordinates.z()};
			shovelerSpatialOsWorkerViewUpdateEntityPosition(view, op.EntityId, position);
		}
	});

	dispatcher.OnRemoveComponent<Position>([&](const worker::RemoveComponentOp& op) {
		shovelerLogInfo("Removing position from entity %lld.", op.EntityId);
		shovelerSpatialOsWorkerViewRemoveEntityPosition(view, op.EntityId);
	});

	dispatcher.OnAddComponent<Model>([&](const worker::AddComponentOp<Model>& op) {
		shovelerLogInfo("Adding model to entity %lld.", op.EntityId);
		ShovelerSpatialOsWorkerViewDrawableConfiguration drawableConfiguration = createDrawableConfiguration(op.Data.drawable());
		ShovelerSpatialOsWorkerViewMaterialConfiguration materialConfiguration = createMaterialConfiguration(op.Data.material());
		shovelerSpatialOsWorkerViewAddEntityModel(view, op.EntityId, drawableConfiguration, materialConfiguration);
	});

	dispatcher.OnComponentUpdate<Model>([&](const worker::ComponentUpdateOp<Model>& op) {
		shovelerLogInfo("Updating model for entity %lld.", op.EntityId);

		ShovelerSpatialOsWorkerViewDrawableConfiguration drawableConfiguration;
		ShovelerSpatialOsWorkerViewDrawableConfiguration *optionalDrawableConfiguration = NULL;
		if(op.Update.drawable()) {
			drawableConfiguration = createDrawableConfiguration(*op.Update.drawable());
			optionalDrawableConfiguration = &drawableConfiguration;
		}

		ShovelerSpatialOsWorkerViewMaterialConfiguration materialConfiguration;
		ShovelerSpatialOsWorkerViewMaterialConfiguration *optionalMaterialConfiguration = NULL;
		if(op.Update.material()) {
			materialConfiguration = createMaterialConfiguration(*op.Update.material());
			optionalMaterialConfiguration = &materialConfiguration;
		}

		shovelerSpatialOsWorkerViewUpdateEntityModel(view, op.EntityId, optionalDrawableConfiguration, optionalMaterialConfiguration);
	});

	dispatcher.OnRemoveComponent<Model>([&](const worker::RemoveComponentOp& op) {
		shovelerLogInfo("Removing model from entity %lld.", op.EntityId);
		shovelerSpatialOsWorkerViewRemoveEntityModel(view, op.EntityId);
	});

	ShovelerLightPoint *pointlight = shovelerLightPointCreate((ShovelerVector3){0, 5, 0}, 1024, 1024, 1, 0.0f, 80.0f, (ShovelerVector3){1.0f, 1.0f, 1.0f});
	shovelerSceneAddLight(game->scene, &pointlight->light);

	while(shovelerGameIsRunning(game) && !disconnected) {
		dispatcher.Process(connection.GetOpList(0));
		shovelerGameRenderFrame(game);
	}
	shovelerLogInfo("Exiting main loop, goodbye.");

	shovelerSpatialOsWorkerViewFree(view);

	shovelerCameraFree(game->camera);
	shovelerSceneFree(game->scene);

	shovelerGameFree(game);
}

static void updateGame(ShovelerGame *game, double dt)
{

}<commit_msg>fixed client build on Windows<commit_after>#include <improbable/standard_library.h>
#include <improbable/worker.h>
#include <shoveler.h>

extern "C" {
#include <shoveler/camera/perspective.h>
#include <shoveler/light/point.h>
#include <shoveler/constants.h>
#include <shoveler/game.h>
#include <shoveler/log.h>
#include <shoveler/types.h>

#include "worker_view.h"
}

using shoveler::Drawable;
using shoveler::DrawableType;
using shoveler::Material;
using shoveler::MaterialType;
using shoveler::Model;
using improbable::Coordinates;
using improbable::Position;

static void updateGame(ShovelerGame *game, double dt);
static ShovelerSpatialOsWorkerViewDrawableConfiguration createDrawableConfiguration(const Drawable& drawable);
static ShovelerSpatialOsWorkerViewMaterialConfiguration createMaterialConfiguration(const Material& material);

int main(int argc, char **argv) {
	if (argc != 4) {
		return 1;
	}

	const char *windowTitle = "ShovelerClient";
	bool fullscreen = false;
	bool vsync = true;
	int samples = 4;
	int width = 640;
	int height = 480;

	ShovelerGame *game = shovelerGameCreate(windowTitle, width, height, samples, fullscreen, vsync);
	if(game == NULL) {
		return EXIT_FAILURE;
	}

	worker::ConnectionParameters parameters;
	parameters.WorkerType = "ShovelerClient";
	parameters.Network.ConnectionType = worker::NetworkConnectionType::kTcp;
	parameters.Network.UseExternalIp = false;

	const std::string workerId = argv[1];
	const std::string hostname = argv[2];
	const std::uint16_t port = static_cast<std::uint16_t>(std::stoi(argv[3]));

	shovelerLogInfo("Connecting as worker %s to %s:%d.", workerId.c_str(), hostname.c_str(), port);
	worker::Connection connection = worker::Connection::ConnectAsync(hostname, port, workerId, parameters).Get();
	bool disconnected = false;
	worker::Dispatcher dispatcher;

	game->camera = shovelerCameraPerspectiveCreate(ShovelerVector3{0.0, 0.0, -1.0}, ShovelerVector3{0.0, 0.0, 1.0}, ShovelerVector3{0.0, 1.0, 0.0}, 2.0f * SHOVELER_PI * 50.0f / 360.0f, (float) width / height, 0.01, 1000);
	game->scene = shovelerSceneCreate();
	game->update = updateGame;
	ShovelerSpatialOsWorkerView *view = shovelerSpatialOsWorkerViewCreate(game->scene);

	dispatcher.OnDisconnect([&](const worker::DisconnectOp& op) {
		shovelerLogError("Disconnected from SpatialOS: %s", op.Reason.c_str());
		disconnected = true;
	});

	dispatcher.OnAddEntity([&](const worker::AddEntityOp& op) {
		shovelerLogInfo("Adding entity %lld.", op.EntityId);
		shovelerSpatialOsWorkerViewAddEntity(view, op.EntityId);
	});

	dispatcher.OnRemoveEntity([&](const worker::RemoveEntityOp& op) {
		shovelerLogInfo("Removing entity %lld.", op.EntityId);
		shovelerSpatialOsWorkerViewRemoveEntity(view, op.EntityId);
	});

	dispatcher.OnAddComponent<Position>([&](const worker::AddComponentOp<Position>& op) {
		shovelerLogInfo("Adding position to entity %lld.", op.EntityId);
		ShovelerVector3 position{(float) op.Data.coords().x(), (float) op.Data.coords().y(), (float) op.Data.coords().z()};
		shovelerSpatialOsWorkerViewAddEntityPosition(view, op.EntityId, position);
	});

	dispatcher.OnComponentUpdate<Position>([&](const worker::ComponentUpdateOp<Position>& op) {
		shovelerLogInfo("Updating position for entity %lld.", op.EntityId);
		if(op.Update.coords()) {
			const Coordinates& coordinates = *op.Update.coords();
			ShovelerVector3 position{(float) coordinates.x(), (float) coordinates.y(), (float) coordinates.z()};
			shovelerSpatialOsWorkerViewUpdateEntityPosition(view, op.EntityId, position);
		}
	});

	dispatcher.OnRemoveComponent<Position>([&](const worker::RemoveComponentOp& op) {
		shovelerLogInfo("Removing position from entity %lld.", op.EntityId);
		shovelerSpatialOsWorkerViewRemoveEntityPosition(view, op.EntityId);
	});

	dispatcher.OnAddComponent<Model>([&](const worker::AddComponentOp<Model>& op) {
		shovelerLogInfo("Adding model to entity %lld.", op.EntityId);
		ShovelerSpatialOsWorkerViewDrawableConfiguration drawableConfiguration = createDrawableConfiguration(op.Data.drawable());
		ShovelerSpatialOsWorkerViewMaterialConfiguration materialConfiguration = createMaterialConfiguration(op.Data.material());
		shovelerSpatialOsWorkerViewAddEntityModel(view, op.EntityId, drawableConfiguration, materialConfiguration);
	});

	dispatcher.OnComponentUpdate<Model>([&](const worker::ComponentUpdateOp<Model>& op) {
		shovelerLogInfo("Updating model for entity %lld.", op.EntityId);

		ShovelerSpatialOsWorkerViewDrawableConfiguration drawableConfiguration;
		ShovelerSpatialOsWorkerViewDrawableConfiguration *optionalDrawableConfiguration = NULL;
		if(op.Update.drawable()) {
			drawableConfiguration = createDrawableConfiguration(*op.Update.drawable());
			optionalDrawableConfiguration = &drawableConfiguration;
		}

		ShovelerSpatialOsWorkerViewMaterialConfiguration materialConfiguration;
		ShovelerSpatialOsWorkerViewMaterialConfiguration *optionalMaterialConfiguration = NULL;
		if(op.Update.material()) {
			materialConfiguration = createMaterialConfiguration(*op.Update.material());
			optionalMaterialConfiguration = &materialConfiguration;
		}

		shovelerSpatialOsWorkerViewUpdateEntityModel(view, op.EntityId, optionalDrawableConfiguration, optionalMaterialConfiguration);
	});

	dispatcher.OnRemoveComponent<Model>([&](const worker::RemoveComponentOp& op) {
		shovelerLogInfo("Removing model from entity %lld.", op.EntityId);
		shovelerSpatialOsWorkerViewRemoveEntityModel(view, op.EntityId);
	});

	ShovelerLightPoint *pointlight = shovelerLightPointCreate(ShovelerVector3{0, 5, 0}, 1024, 1024, 1, 0.0f, 80.0f, ShovelerVector3{1.0f, 1.0f, 1.0f});
	shovelerSceneAddLight(game->scene, &pointlight->light);

	while(shovelerGameIsRunning(game) && !disconnected) {
		dispatcher.Process(connection.GetOpList(0));
		shovelerGameRenderFrame(game);
	}
	shovelerLogInfo("Exiting main loop, goodbye.");

	shovelerSpatialOsWorkerViewFree(view);

	shovelerCameraFree(game->camera);
	shovelerSceneFree(game->scene);

	shovelerGameFree(game);
}

static void updateGame(ShovelerGame *game, double dt)
{

}
{'fraction_non_alphanumeric': 0.1289308176100629, 'fraction_numerical': 0.013406156901688183, 'mean_word_length': 7.540636042402827, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 59, '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': '3196288', 'n_tokens_mistral': 4066, 'n_tokens_neox': 3886, 'n_words': 678}