- updated copyright headers is some files that had them missing

- added a new language string for battle end screen
This commit is contained in:
Mark Vejvoda
2012-08-02 00:57:28 +00:00
parent 39c85914e9
commit ee2c02610d
38 changed files with 790 additions and 20 deletions

View File

@@ -1,3 +1,10 @@
// ==============================================================
// This file is part of MegaGlest Shared Library (www.megaglest.org)
//
// Copyright (C) 2012 Mark Vejvoda, Titus Tscharntke
// The Megaglest Team, under GNU GPL v3.0
// ==============================================================
#include "FileReader.h"
namespace Shared {

View File

@@ -0,0 +1,62 @@
// ==============================================================
// This file is part of MegaGlest Shared Library (www.megaglest.org)
//
// Copyright (C) 2012 Mark Vejvoda, Titus Tscharntke
// The Megaglest Team, under GNU GPL v3.0
// ==============================================================
#include "buffer.h"
#include "leak_dumper.h"
namespace Shared{ namespace Graphics{
// =====================================================
// class VertexBuffer
// =====================================================
VertexBuffer::VertexBuffer(){
positionPointer= NULL;
normalPointer= NULL;
for(int i= 0; i<texCoordCount; ++i){
texCoordPointers[i]= NULL;
texCoordCoordCounts[i]= -1;
}
for(int i= 0; i<attribCount; ++i){
attribPointers[i]= NULL;
attribCoordCounts[i]= -1;
}
}
void VertexBuffer::setPositionPointer(void *pointer){
positionPointer= pointer;
}
void VertexBuffer::setNormalPointer(void *pointer){
normalPointer= pointer;
}
void VertexBuffer::setTexCoordPointer(void *pointer, int texCoordIndex, int coordCount){
texCoordPointers[texCoordIndex]= pointer;
texCoordCoordCounts[texCoordIndex]= coordCount;
}
void VertexBuffer::setAttribPointer(void *pointer, int attribIndex, int coordCount, const string &name){
attribPointers[attribIndex]= pointer;
attribCoordCounts[attribIndex]= coordCount;
attribNames[attribIndex]= name;
}
// =====================================================
// class IndexBuffer
// =====================================================
IndexBuffer::IndexBuffer(){
indexPointer= NULL;
}
void IndexBuffer::setIndexPointer(void *pointer){
indexPointer= pointer;
}
}}//end namespace

View File

@@ -1,3 +1,13 @@
// This file is part of MegaGlest Shared Library (www.megaglest.org)
//
// Copyright (C) 2012 Mark Vejvoda
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
#include "context_d3d9.h"
#include <cassert>
@@ -70,4 +80,4 @@ void ContextD3d9::reset(){
}
}}}//end namespace
}}}//end namespace

View File

@@ -1,3 +1,10 @@
// ==============================================================
// This file is part of MegaGlest Shared Library (www.megaglest.org)
//
// Copyright (C) 2012 Mark Vejvoda, Titus Tscharntke
// The Megaglest Team, under GNU GPL v3.0
// ==============================================================
#include "d3d9_util.h"
namespace Shared{ namespace Graphics{ namespace D3d9{

View File

@@ -1,3 +1,10 @@
// ==============================================================
// This file is part of MegaGlest Shared Library (www.megaglest.org)
//
// Copyright (C) 2012 Mark Vejvoda, Titus Tscharntke
// The Megaglest Team, under GNU GPL v3.0
// ==============================================================
#include "font_d3d9.h"
#include <stdexcept>
@@ -35,4 +42,4 @@ void Font2DD3d9::end(){
}
}}}//end namespace
}}}//end namespace

View File

@@ -0,0 +1,180 @@
// ==============================================================
// This file is part of MegaGlest Shared Library (www.megaglest.org)
//
// Copyright (C) 2012 Mark Vejvoda, Titus Tscharntke
// The Megaglest Team, under GNU GPL v3.0
// ==============================================================
#include "model_renderer_d3d9.h"
#include <cassert>
#include "graphics_interface.h"
#include "context_d3d9.h"
#include "texture_d3d9.h"
#include "interpolation.h"
#include "d3d9_util.h"
#include "leak_dumper.h"
namespace Shared{ namespace Graphics{ namespace D3d9{
// ===============================================
// class ModelRendererD3d9
// ===============================================
D3DVERTEXELEMENT9 d3dVertexElementsPNT[]=
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
{0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
D3DDECL_END()
};
D3DVERTEXELEMENT9 d3dVertexElementsPNTT[]=
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
{0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
{0, 32, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0},
D3DDECL_END()
};
ModelRendererD3d9::ModelRendererD3d9(){
rendering= false;
GraphicsInterface &gi= GraphicsInterface::getInstance();
d3dDevice= static_cast<ContextD3d9*>(gi.getCurrentContext())->getD3dDevice();
bufferPointCount= 0;
bufferIndexCount= 0;
D3DCALL(d3dDevice->CreateVertexDeclaration(d3dVertexElementsPNT, &d3dVertexDeclarationPNT));
D3DCALL(d3dDevice->CreateVertexDeclaration(d3dVertexElementsPNTT, &d3dVertexDeclarationPNTT));
readyBuffers(defBufferPointCount, defBufferIndexCount);
}
ModelRendererD3d9::~ModelRendererD3d9(){
d3dVertexBuffer->Release();
}
void ModelRendererD3d9::begin(bool renderNormals, bool renderTextures, bool renderColors){
rendering= true;
}
void ModelRendererD3d9::end(){
rendering= false;
}
void ModelRendererD3d9::render(const Model *model){
assert(rendering);
//render every mesh
for(uint32 i=0; i<model->getMeshCount(); ++i){
renderMesh(model->getMesh(i));
}
}
void ModelRendererD3d9::renderNormalsOnly(const Model *model){
}
// ====================== Private ===============================================
void ModelRendererD3d9::renderMesh(const Mesh *mesh){
CustomVertexPNTT *vertices;
uint32 *indices;
readyBuffers(mesh->getVertexCount(), mesh->getIndexCount());
//lock vertex buffer
D3DCALL(d3dVertexBuffer->Lock(0, mesh->getVertexCount()*sizeof(CustomVertexPNTT), (void**) &vertices, 0));
//copy data vertex buffer
const InterpolationData *interpolationData= mesh->getInterpolationData();
for(int i=0; i<mesh->getVertexCount(); ++i){
vertices[i].vertex= interpolationData->getVertices()[i];
vertices[i].normal= interpolationData->getNormals()[i];
Vec2f texCoord= mesh->getTexCoords()[i];
vertices[i].texCoord= Vec2f(texCoord.x, texCoord.y);
}
if(mesh->getTangents()!=NULL){
for(int i=0; i<mesh->getVertexCount(); ++i){
vertices[i].tangent= mesh->getTangents()[i];
}
}
//unlock vertex buffer
D3DCALL(d3dVertexBuffer->Unlock());
//lock index buffer
D3DCALL(d3dIndexBuffer->Lock(0, mesh->getIndexCount()*sizeof(uint32), (void**) &indices, 0));
//copy data
for(int i=0; i<mesh->getIndexCount(); i+=3){
indices[i]= mesh->getIndices()[i];
indices[i+1]= mesh->getIndices()[i+2];
indices[i+2]= mesh->getIndices()[i+1];
}
//unlock
D3DCALL(d3dIndexBuffer->Unlock());
//set stream data
D3DCALL(d3dDevice->SetStreamSource(0, d3dVertexBuffer, 0, sizeof(CustomVertexPNTT)));
D3DCALL(d3dDevice->SetVertexDeclaration(mesh->getTangents()==NULL? d3dVertexDeclarationPNT: d3dVertexDeclarationPNTT));
D3DCALL(d3dDevice->SetIndices(d3dIndexBuffer));
//set textures
int textureUnit= 0;
for(int i=0; i<meshTextureCount; ++i){
if(mesh->getTexture(i)!=NULL){
const Texture2DD3d9* texture2DD3d9= static_cast<const Texture2DD3d9*>(mesh->getTexture(i));
D3DCALL(d3dDevice->SetTexture(textureUnit, texture2DD3d9->getD3dTexture()));
++textureUnit;
}
}
//render
D3DCALL(d3dDevice->BeginScene());
D3DCALL(d3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, mesh->getVertexCount(), 0, mesh->getIndexCount()/3));
D3DCALL(d3dDevice->EndScene());
//reset textures
for(int i=0; i<meshTextureCount; ++i){
D3DCALL(d3dDevice->SetTexture(i, NULL));
}
}
void ModelRendererD3d9::readyBuffers(int newPointCount, int newIndexCount){
//vertices, if the buffer is to small allocate a new buffer
if(bufferPointCount<newPointCount){
bufferPointCount= newPointCount;
D3DCALL(d3dDevice->CreateVertexBuffer(
bufferPointCount*sizeof(CustomVertexPNTT),
0,
0,
D3DPOOL_MANAGED,
&d3dVertexBuffer,
NULL));
}
//indices
if(bufferIndexCount<newIndexCount){
bufferIndexCount= newIndexCount;
D3DCALL(d3dDevice->CreateIndexBuffer(
bufferIndexCount*sizeof(uint32),
0,
D3DFMT_INDEX32,
D3DPOOL_MANAGED,
&d3dIndexBuffer,
NULL));
}
}
}}}//end namespace

View File

@@ -1,3 +1,10 @@
// ==============================================================
// This file is part of MegaGlest Shared Library (www.megaglest.org)
//
// Copyright (C) 2012 Mark Vejvoda, Titus Tscharntke
// The Megaglest Team, under GNU GPL v3.0
// ==============================================================
#include "shader_d3d9.h"
#include <fstream>

View File

@@ -0,0 +1,47 @@
// ==============================================================
// This file is part of MegaGlest Shared Library (www.megaglest.org)
//
// Copyright (C) 2012 Mark Vejvoda, Titus Tscharntke
// The Megaglest Team, under GNU GPL v3.0
// ==============================================================
#include "text_renderer_d3d9.h"
#include <d3d9.h>
#include <d3d9types.h>
#include "font_d3d9.h"
#include "d3d9_util.h"
#include "leak_dumper.h"
namespace Shared{ namespace Graphics{ namespace D3d9{
// ===============================================
// class TextRenderer2DD3d9
// ===============================================
void TextRenderer2DD3d9::begin(const Font2D *font){
this->font= font;
this->color= Vec4f(1.0f);
}
void TextRenderer2DD3d9::render(const string &text, int x, int y, bool centered){
RECT rect;
rect.bottom= y;
rect.left= x;
rect.top= y;
rect.right= x;
D3DCOLOR d3dColor= D3DCOLOR_ARGB(
static_cast<int>(color.w*255),
static_cast<int>(color.x*255),
static_cast<int>(color.y*255),
static_cast<int>(color.z*255));
static_cast<const Font2DD3d9*>(font)->getD3dFont()->DrawText(text.c_str(), -1, &rect, DT_NOCLIP, d3dColor);
}
void TextRenderer2DD3d9::end(){
}
}}}//end namespace

View File

@@ -1,3 +1,10 @@
// ==============================================================
// This file is part of MegaGlest Shared Library (www.megaglest.org)
//
// Copyright (C) 2012 Mark Vejvoda, Titus Tscharntke
// The Megaglest Team, under GNU GPL v3.0
// ==============================================================
#include "texture_d3d9.h"
#include <stdexcept>
@@ -189,4 +196,4 @@ void TextureCubeD3d9::end(){
}
}
}}}//end namespace
}}}//end namespace

View File

@@ -1,3 +1,15 @@
// ==============================================================
// This file is part of MegaGlest Shared Library (www.megaglest.org)
//
// Copyright (C) 2012 Mark Vejvoda, Titus Tscharntke
// 2001-2008 Martiño Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
#include "randomgen.h"
#include <cassert>
#include "util.h"