<commit_before>#include <assert.h> // assert
#include <stdlib.h> // malloc free

#include <shoveler/drawable/cube.h>
#include <shoveler/drawable/point.h>
#include <shoveler/drawable/quad.h>
#include <shoveler/material/color.h>
#include <shoveler/material/particle.h>
#include <shoveler/material/texture.h>
#include <shoveler/spatialos/worker/view/base/position.h>
#include <shoveler/spatialos/worker/view/base/view.h>
#include <shoveler/log.h>
#include <shoveler/model.h>

#include "shoveler/spatialos/worker/view/visual/model.h"
#include "shoveler/spatialos/worker/view/visual/scene.h"

typedef struct {
	ShovelerModel *model;
	ShovelerSpatialosWorkerViewComponentCallback *positionCallback;
} ModelComponentData;

static ShovelerDrawable *getDrawable(ShovelerSpatialosWorkerView *view, ShovelerSpatialosWorkerViewDrawableConfiguration configuration);
static ShovelerMaterial *createMaterial(ShovelerSpatialosWorkerView *view, ShovelerSpatialosWorkerViewMaterialConfiguration configuration);
static void updatePositionIfAvailable(ShovelerSpatialosWorkerViewEntity *entity, ModelComponentData *modelComponentData);
static void positionCallback(ShovelerSpatialosWorkerViewComponent *positionComponent, ShovelerSpatialosWorkerViewComponentCallbackType callbackType, void *modelComponentDataPointer);
static void freeComponent(ShovelerSpatialosWorkerViewComponent *component);

bool shovelerSpatialosWorkerViewAddEntityModel(ShovelerSpatialosWorkerView *view, long long int entityId, ShovelerSpatialosWorkerViewModelConfiguration modelConfiguration)
{
	assert(shovelerSpatialosWorkerViewHasScene(view));

	ShovelerSpatialosWorkerViewEntity *entity = shovelerSpatialosWorkerViewGetEntity(view, entityId);
	if(entity == NULL) {
		shovelerLogWarning("Trying to add model to non existing entity %lld, ignoring.", entityId);
		return false;
	}

	ShovelerSpatialosWorkerViewComponent *component = shovelerSpatialosWorkerViewEntityGetComponent(entity, "model");
	if(component != NULL) {
		shovelerLogWarning("Trying to add model to entity %lld which already has a model, ignoring.", entityId);
		return false;
	}

	ShovelerDrawable *drawable = getDrawable(view, modelConfiguration.drawable);
	if(drawable == NULL) {
		shovelerLogWarning("Trying to add model to entity %lld but failed to create drawable, ignoring.", entityId);
		return false;
	}

	ShovelerMaterial *material = createMaterial(view, modelConfiguration.material);
	if(material == NULL) {
		shovelerLogWarning("Trying to add model to entity %lld but failed to create material, ignoring.", entityId);
		return false;
	}

	ShovelerModel *model = shovelerModelCreate(drawable, material);
	model->rotation = modelConfiguration.rotation;
	model->scale = modelConfiguration.scale;
	model->visible = modelConfiguration.visible;
	model->emitter = modelConfiguration.emitter;
	model->screenspace = modelConfiguration.screenspace;
	model->castsShadow = modelConfiguration.castsShadow;
	model->polygonMode = modelConfiguration.polygonMode;

	ShovelerScene *scene = shovelerSpatialosWorkerViewGetScene(view);
	shovelerSceneAddModel(scene, model);

	ModelComponentData *modelComponentData = malloc(sizeof(ModelComponentData));
	modelComponentData->model = model;
	modelComponentData->positionCallback = shovelerSpatialosWorkerViewEntityAddCallback(entity, "position", &positionCallback, modelComponentData);

	if (!shovelerSpatialosWorkerViewEntityAddComponent(entity, "model", model, &freeComponent)) {
		freeComponent(component);
		return false;
	}
	return true;
}

bool shovelerSpatialosWorkerViewUpdateEntityModelDrawable(ShovelerSpatialosWorkerView *view, long long int entityId, ShovelerSpatialosWorkerViewDrawableConfiguration drawableConfiguration)
{
	assert(shovelerSpatialosWorkerViewHasScene(view));
<commit_msg>properly add component data instead of model itself for model component<commit_after>#include <assert.h> // assert
#include <stdlib.h> // malloc free

#include <shoveler/drawable/cube.h>
#include <shoveler/drawable/point.h>
#include <shoveler/drawable/quad.h>
#include <shoveler/material/color.h>
#include <shoveler/material/particle.h>
#include <shoveler/material/texture.h>
#include <shoveler/spatialos/worker/view/base/position.h>
#include <shoveler/spatialos/worker/view/base/view.h>
#include <shoveler/log.h>
#include <shoveler/model.h>

#include "shoveler/spatialos/worker/view/visual/model.h"
#include "shoveler/spatialos/worker/view/visual/scene.h"

typedef struct {
	ShovelerModel *model;
	ShovelerSpatialosWorkerViewComponentCallback *positionCallback;
} ModelComponentData;

static ShovelerDrawable *getDrawable(ShovelerSpatialosWorkerView *view, ShovelerSpatialosWorkerViewDrawableConfiguration configuration);
static ShovelerMaterial *createMaterial(ShovelerSpatialosWorkerView *view, ShovelerSpatialosWorkerViewMaterialConfiguration configuration);
static void updatePositionIfAvailable(ShovelerSpatialosWorkerViewEntity *entity, ModelComponentData *modelComponentData);
static void positionCallback(ShovelerSpatialosWorkerViewComponent *positionComponent, ShovelerSpatialosWorkerViewComponentCallbackType callbackType, void *modelComponentDataPointer);
static void freeComponent(ShovelerSpatialosWorkerViewComponent *component);

bool shovelerSpatialosWorkerViewAddEntityModel(ShovelerSpatialosWorkerView *view, long long int entityId, ShovelerSpatialosWorkerViewModelConfiguration modelConfiguration)
{
	assert(shovelerSpatialosWorkerViewHasScene(view));

	ShovelerSpatialosWorkerViewEntity *entity = shovelerSpatialosWorkerViewGetEntity(view, entityId);
	if(entity == NULL) {
		shovelerLogWarning("Trying to add model to non existing entity %lld, ignoring.", entityId);
		return false;
	}

	ShovelerSpatialosWorkerViewComponent *component = shovelerSpatialosWorkerViewEntityGetComponent(entity, "model");
	if(component != NULL) {
		shovelerLogWarning("Trying to add model to entity %lld which already has a model, ignoring.", entityId);
		return false;
	}

	ShovelerDrawable *drawable = getDrawable(view, modelConfiguration.drawable);
	if(drawable == NULL) {
		shovelerLogWarning("Trying to add model to entity %lld but failed to create drawable, ignoring.", entityId);
		return false;
	}

	ShovelerMaterial *material = createMaterial(view, modelConfiguration.material);
	if(material == NULL) {
		shovelerLogWarning("Trying to add model to entity %lld but failed to create material, ignoring.", entityId);
		return false;
	}

	ShovelerModel *model = shovelerModelCreate(drawable, material);
	model->rotation = modelConfiguration.rotation;
	model->scale = modelConfiguration.scale;
	model->visible = modelConfiguration.visible;
	model->emitter = modelConfiguration.emitter;
	model->screenspace = modelConfiguration.screenspace;
	model->castsShadow = modelConfiguration.castsShadow;
	model->polygonMode = modelConfiguration.polygonMode;

	ShovelerScene *scene = shovelerSpatialosWorkerViewGetScene(view);
	shovelerSceneAddModel(scene, model);

	ModelComponentData *modelComponentData = malloc(sizeof(ModelComponentData));
	modelComponentData->model = model;
	modelComponentData->positionCallback = shovelerSpatialosWorkerViewEntityAddCallback(entity, "position", &positionCallback, modelComponentData);

	if (!shovelerSpatialosWorkerViewEntityAddComponent(entity, "model", modelComponentData, &freeComponent)) {
		freeComponent(component);
		return false;
	}
	return true;
}

bool shovelerSpatialosWorkerViewUpdateEntityModelDrawable(ShovelerSpatialosWorkerView *view, long long int entityId, ShovelerSpatialosWorkerViewDrawableConfiguration drawableConfiguration)
{
	assert(shovelerSpatialosWorkerViewHasScene(view));

{'fraction_non_alphanumeric': 0.08924575490325129, 'fraction_numerical': 0.0, 'mean_word_length': 8.533249686323714, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 45, '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': '5699469', 'n_tokens_mistral': 2307, 'n_tokens_neox': 2261, 'n_words': 442}