#pragma once

#include "Sockets.hpp"
#include "SceneDesc.hpp"
#include "RayTracer.hpp"

#define RSI_DEBUG

enum PacketType
{
	CLIENT_REQUEST,
	SERVER_SCENE_NAME,
	CLIENT_READY,
	SERVER_TASK,
	CLIENT_RESULT,
	SERVER_END,
	CLIENT_END,
	SERVER_REPEAT,
	_PACKET_TYPE_SIZE
};

struct PacketHeader
{
	NIne::NUint32 uPacketType;
	NIne::NUint32 uPacketSize;
};

struct PacketRaytracerParamsTail
{
	NIne::NUint32 uParamsStructSize;	// the tail is params struct
};

struct PacketRaytracerParams
{
	PacketHeader header;
	PacketRaytracerParamsTail tail;
};

struct PacketTaskTail
{
	NIne::NUint32 uTaskIndex, uPackX, uPackY, uWidth, uHeight, uPackSize;
};

struct PacketTask
{
	PacketHeader header;
	PacketTaskTail tail;	
};

struct PacketResultTail
{
	NIne::NUint32 uTaskIndex;
	NIne::NUint32 uResultSize;
};

struct PacketResult
{
	PacketHeader header;
	PacketResultTail tail;
};

// Server side
const NIne::NUint32 PACK_SIZE = 64;

struct Task
{
	NIne::NUint32 uTaskIndex, uPackX, uPackY, uWidth, uHeight, uPitch;
	NIne::NUint8* pDestination;
	bool bDone;
	bool bReserved;
	NIne::NUint32 uNext;
};

const NIne::NUint32 HEADER_SIZES[] = { sizeof(PacketHeader),
							   sizeof(PacketRaytracerParams),
							   sizeof(PacketHeader),
							   sizeof(PacketTask),
							   sizeof(PacketResult),
							   sizeof(PacketHeader),
							   sizeof(PacketHeader),
							   sizeof(PacketHeader)};