<commit_before>// 
// Copyright (C) 2011-2015 <NAME>
// 
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
// 
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Library General Public License for more details.
// 
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the
// Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
// Boston, MA  02110-1301, USA.
// 

#include <stdio.h>
#include <RenderContext.h>
#include <Surface.h>
#include "TextureShader.h"


struct FileHeader
{
	unsigned int fileSize;
	unsigned int numTextures;
	unsigned int numMeshes;
};

struct TextureEntry
{
	unsigned int offset;
	unsigned int mipLevels;
	short width;
	short height;
};

struct MeshEntry
{
	unsigned int offset;
	unsigned int textureId;
	unsigned int numVertices;
	unsigned int numIndices;
};

const int kAttrsPerVertex = 8;
const int kBlockSize = 512;
const int kFbWidth = 1024;
const int kFbHeight = 768;
static volatile unsigned int * const REGISTERS = (volatile unsigned int*) 0xffff0000;

void readBlock(unsigned int blockAddress, void *out)
{
	int i;
	unsigned int *ptr = (unsigned int*) out;
	
	REGISTERS[0x30 / 4] = blockAddress;
	for (i = 0; i < kBlockSize / 4; i++)
		*ptr++ = REGISTERS[0x34 / 4];
}

char *readResourceFile()
{
	char tmp[kBlockSize];
	unsigned int fileSize;
	char *resourceData;

	// Read the first block to determine how large the rest of the file is.
	readBlock(0, tmp);
	fileSize = ((FileHeader*) tmp)->fileSize;

	printf("reading resource file, %d bytes\n", fileSize);
	
	resourceData = (char*) malloc(fileSize + kBlockSize);
	memcpy(resourceData, tmp, kBlockSize);
	for (int i = 1, len=(fileSize + kBlockSize - 1) / kBlockSize; i < len; i++)
		readBlock(i * kBlockSize, resourceData + i * kBlockSize);

	return resourceData;
}

int main()
{
	// Set up resource data
	char *resourceData = readResourceFile();
	const FileHeader *resourceHeader = (FileHeader*) resourceData;
	const TextureEntry *texHeader = (TextureEntry*)(resourceData + sizeof(FileHeader));
	const MeshEntry *meshHeader = (MeshEntry*)(resourceData + sizeof(FileHeader) + resourceHeader->numTextures
		* sizeof(TextureEntry));
	Texture **textures = new Texture*[resourceHeader->numTextures];

	printf("%d textures %d meshes\n", resourceHeader->numTextures, resourceHeader->numMeshes);

	// Create texture objects
	for (unsigned int textureIndex = 0; textureIndex < resourceHeader->numTextures; textureIndex++)
	{
		textures[textureIndex] = new Texture();
		textures[textureIndex]->enableBilinearFiltering(true);
		int offset = texHeader[textureIndex].offset;
		for (int mipLevel = 0; mipLevel < texHeader[textureIndex].mipLevels; mipLevel++)
		{
			int width = texHeader[textureIndex].width >> mipLevel;
			int height = texHeader[textureIndex].height >> mipLevel;
			Surface *surface = new Surface(width, height, resourceData + offset);
			textures[textureIndex]->setMipSurface(mipLevel, surface);
			offset += width * height * 4;
		}
	}
	
	// Set up render state
	RenderContext *context = new RenderContext(0x1000000);
	RenderTarget *renderTarget = new RenderTarget();
	Surface *colorBuffer = new Surface(kFbWidth, kFbHeight, (void*) 0x200000);
	Surface *zBuffer = new Surface(kFbWidth, kFbHeight);
	renderTarget->setColorBuffer(colorBuffer);
	renderTarget->setZBuffer(zBuffer);
	context->bindTarget(renderTarget);
	context->enableZBuffer(true);
	context->bindShader(new TextureVertexShader(), new TexturePixelShader());
	context->setClearColor(0.52, 0.80, 0.98);

	Matrix projectionMatrix = Matrix::getProjectionMatrix(kFbWidth, kFbHeight);
<commit_msg>viewobj: fix warning<commit_after>// 
// Copyright (C) 2011-2015 <NAME>
// 
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
// 
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Library General Public License for more details.
// 
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the
// Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
// Boston, MA  02110-1301, USA.
// 

#include <stdio.h>
#include <RenderContext.h>
#include <Surface.h>
#include "TextureShader.h"


struct FileHeader
{
	unsigned int fileSize;
	unsigned int numTextures;
	unsigned int numMeshes;
};

struct TextureEntry
{
	unsigned int offset;
	unsigned int mipLevels;
	short width;
	short height;
};

struct MeshEntry
{
	unsigned int offset;
	unsigned int textureId;
	unsigned int numVertices;
	unsigned int numIndices;
};

const int kAttrsPerVertex = 8;
const int kBlockSize = 512;
const int kFbWidth = 1024;
const int kFbHeight = 768;
static volatile unsigned int * const REGISTERS = (volatile unsigned int*) 0xffff0000;

void readBlock(unsigned int blockAddress, void *out)
{
	int i;
	unsigned int *ptr = (unsigned int*) out;
	
	REGISTERS[0x30 / 4] = blockAddress;
	for (i = 0; i < kBlockSize / 4; i++)
		*ptr++ = REGISTERS[0x34 / 4];
}

char *readResourceFile()
{
	char tmp[kBlockSize];
	unsigned int fileSize;
	char *resourceData;

	// Read the first block to determine how large the rest of the file is.
	readBlock(0, tmp);
	fileSize = ((FileHeader*) tmp)->fileSize;

	printf("reading resource file, %d bytes\n", fileSize);
	
	resourceData = (char*) malloc(fileSize + kBlockSize);
	memcpy(resourceData, tmp, kBlockSize);
	for (int i = 1, len=(fileSize + kBlockSize - 1) / kBlockSize; i < len; i++)
		readBlock(i * kBlockSize, resourceData + i * kBlockSize);

	return resourceData;
}

int main()
{
	// Set up resource data
	char *resourceData = readResourceFile();
	const FileHeader *resourceHeader = (FileHeader*) resourceData;
	const TextureEntry *texHeader = (TextureEntry*)(resourceData + sizeof(FileHeader));
	const MeshEntry *meshHeader = (MeshEntry*)(resourceData + sizeof(FileHeader) + resourceHeader->numTextures
		* sizeof(TextureEntry));
	Texture **textures = new Texture*[resourceHeader->numTextures];

	printf("%d textures %d meshes\n", resourceHeader->numTextures, resourceHeader->numMeshes);

	// Create texture objects
	for (unsigned int textureIndex = 0; textureIndex < resourceHeader->numTextures; textureIndex++)
	{
		textures[textureIndex] = new Texture();
		textures[textureIndex]->enableBilinearFiltering(true);
		int offset = texHeader[textureIndex].offset;
		for (unsigned int mipLevel = 0; mipLevel < texHeader[textureIndex].mipLevels; mipLevel++)
		{
			int width = texHeader[textureIndex].width >> mipLevel;
			int height = texHeader[textureIndex].height >> mipLevel;
			Surface *surface = new Surface(width, height, resourceData + offset);
			textures[textureIndex]->setMipSurface(mipLevel, surface);
			offset += width * height * 4;
		}
	}
	
	// Set up render state
	RenderContext *context = new RenderContext(0x1000000);
	RenderTarget *renderTarget = new RenderTarget();
	Surface *colorBuffer = new Surface(kFbWidth, kFbHeight, (void*) 0x200000);
	Surface *zBuffer = new Surface(kFbWidth, kFbHeight);
	renderTarget->setColorBuffer(colorBuffer);
	renderTarget->setZBuffer(zBuffer);
	context->bindTarget(renderTarget);
	context->enableZBuffer(true);
	context->bindShader(new TextureVertexShader(), new TexturePixelShader());
	context->setClearColor(0.52, 0.80, 0.98);

	Matrix projectionMatrix = Matrix::getProjectionMatrix(kFbWidth, kFbHeight);

{'fraction_non_alphanumeric': 0.1115702479338843, 'fraction_numerical': 0.019033308289506636, 'mean_word_length': 4.821428571428571, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 47, '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': '946693', 'n_tokens_mistral': 2614, 'n_tokens_neox': 2416, 'n_words': 801}