// Copyright (c) 2023 Alex Diener. All rights reserved.

#include "PROJECT_NAME/Utilities.h"
#include <stdint.h>

void memxor(void * toUntyped, const void * fromUntyped, size_t size) {
	uint8_t * to = toUntyped;
	const uint8_t * from = fromUntyped;
	for (size_t byteIndex = 0; byteIndex < size; byteIndex++) {
		to[byteIndex] ^= from[byteIndex];
	}
}

bool isMoveBlockedAtPosition(RoomState * roomState, Vector2i position) {
	TilePropertyBits tileProperties = RoomState_getTilePropertiesAtPosition(roomState, position);
	if ((tileProperties & TILE_STATIC_WALL) || !(tileProperties & TILE_STATIC_FLOOR)) {
		return true;
	}
	unsigned int entityCount = RoomState_getEntityCountAtPosition(roomState, position);
	for (unsigned int entityIndex = 0; entityIndex < entityCount; entityIndex++) {
		GameEntity * entity = RoomState_getEntityAtPositionAtIndex(roomState, position, entityIndex);
		if (!entity->markedForRemoval && call_virtual(getComponent, entity, COMPONENT_COLLIDABLE) != NULL) {
			return true;
		}
	}
	return false;
}
