1
1
forked from 0ad/0ad

ran newline stomper; no real changes

This was SVN commit r423.
This commit is contained in:
janwas 2004-06-08 12:10:51 +00:00
parent fec51baee5
commit 8d52add5ea
11 changed files with 165 additions and 142 deletions

View File

@ -9,8 +9,8 @@
#include "precompiled.h" #include "precompiled.h"
#include "Patch.h" #include "Patch.h"
#include "MiniPatch.h" #include "MiniPatch.h"
#include "Terrain.h" #include "Terrain.h"
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Constructor // Constructor

View File

@ -94,18 +94,18 @@ static CVector3D SkinPoint(const CVector3D& pos,const SVertexBlend& blend,
// SkinPoint: skin the given point using the given blend and matrix data // SkinPoint: skin the given point using the given blend and matrix data
static CVector3D SkinPoint(const CVector3D& pos,const SVertexBlend& blend, static CVector3D SkinPoint(const CVector3D& pos,const SVertexBlend& blend,
const CMatrix3D* bonestates) const CMatrix3D* bonestates)
{ {
CVector3D result,tmp; CVector3D result,tmp;
// must have at least one valid bone if we're using SkinPoint // must have at least one valid bone if we're using SkinPoint
assert(blend.m_Bone[0]!=0xff); assert(blend.m_Bone[0]!=0xff);
const CMatrix3D& m=bonestates[blend.m_Bone[0]];
m.Transform(pos,result);
result*=blend.m_Weight[0];
const CMatrix3D& m=bonestates[blend.m_Bone[0]];
m.Transform(pos,result);
result*=blend.m_Weight[0];
for (int i=1;i<SVertexBlend::SIZE && blend.m_Bone[i]!=0xff;i++) { for (int i=1;i<SVertexBlend::SIZE && blend.m_Bone[i]!=0xff;i++) {
const CMatrix3D& m=bonestates[blend.m_Bone[i]]; const CMatrix3D& m=bonestates[blend.m_Bone[i]];
m.Transform(pos,tmp); m.Transform(pos,tmp);
result+=tmp*blend.m_Weight[i]; result+=tmp*blend.m_Weight[i];
} }
@ -233,7 +233,7 @@ void CModel::GenerateBoneMatrices()
if (prop.m_Point->m_BoneIndex!=0xff) { if (prop.m_Point->m_BoneIndex!=0xff) {
proptransform.Concatenate(m_BoneMatrices[prop.m_Point->m_BoneIndex]); proptransform.Concatenate(m_BoneMatrices[prop.m_Point->m_BoneIndex]);
} else { } else {
proptransform.Concatenate(transform); proptransform.Concatenate(transform);
} }
prop.m_Model->SetTransform(proptransform); prop.m_Model->SetTransform(proptransform);
} }
@ -339,7 +339,7 @@ void CModel::SetTransform(const CMatrix3D& transform)
if (prop.m_Point->m_BoneIndex!=0xff) { if (prop.m_Point->m_BoneIndex!=0xff) {
proptransform.Concatenate(m_BoneMatrices[prop.m_Point->m_BoneIndex]); proptransform.Concatenate(m_BoneMatrices[prop.m_Point->m_BoneIndex]);
} else { } else {
proptransform.Concatenate(transform); proptransform.Concatenate(transform);
} }
prop.m_Model->SetTransform(proptransform); prop.m_Model->SetTransform(proptransform);
} }

View File

@ -4,7 +4,7 @@
#include "ObjectManager.h" #include "ObjectManager.h"
#include "Model.h" #include "Model.h"
#include "ModelDef.h" #include "ModelDef.h"
#include "CLogger.h" #include "CLogger.h"
#include "UnitManager.h" #include "UnitManager.h"
@ -104,12 +104,12 @@ bool CObjectEntry::BuildModel()
CModel* propmodel=oe->m_Model->Clone(); CModel* propmodel=oe->m_Model->Clone();
m_Model->AddProp(proppoint,propmodel); m_Model->AddProp(proppoint,propmodel);
if (oe->m_WalkAnim) propmodel->SetAnimation(oe->m_WalkAnim); if (oe->m_WalkAnim) propmodel->SetAnimation(oe->m_WalkAnim);
} else { } else {
LOG(ERROR,"Failed to build prop model \"%s\" on actor \"%s\"\n",(const char*) m_Name,(const char*) prop.m_ModelName); LOG(ERROR,"Failed to build prop model \"%s\" on actor \"%s\"\n",(const char*) m_Name,(const char*) prop.m_ModelName);
} }
} }
} else { } else {
LOG(ERROR,"Failed to matching prop point called \"%s\" in model \"%s\"\n",prop.m_PropPointName,(const char*) modelfilename); LOG(ERROR,"Failed to matching prop point called \"%s\" in model \"%s\"\n",prop.m_PropPointName,(const char*) modelfilename);
} }
} }

View File

@ -12,9 +12,9 @@ class CSkeletonAnim;
class CObjectEntry class CObjectEntry
{ {
public: public:
struct Anim { struct Anim {
// constructor // constructor
Anim() : m_Speed(1), m_AnimData(0) {} Anim() : m_Speed(1), m_AnimData(0) {}
// name of the animation - "Idle", "Run", etc // name of the animation - "Idle", "Run", etc
CStr m_AnimName; CStr m_AnimName;

View File

@ -8,23 +8,23 @@
#ifndef _PATCH_H #ifndef _PATCH_H
#define _PATCH_H #define _PATCH_H
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Terrain Constants: // Terrain Constants:
// //
// PATCH_SIZE: number of tiles in each patch // PATCH_SIZE: number of tiles in each patch
const int PATCH_SIZE = 16; const int PATCH_SIZE = 16;
// CELL_SIZE: size of each tile in x and z // CELL_SIZE: size of each tile in x and z
const int CELL_SIZE = 4; const int CELL_SIZE = 4;
// HEIGHT_SCALE: vertical scale of terrain - terrain has a coordinate range of // HEIGHT_SCALE: vertical scale of terrain - terrain has a coordinate range of
// 0 to 65536*HEIGHT_SCALE // 0 to 65536*HEIGHT_SCALE
const float HEIGHT_SCALE = 0.35f/256.0f; const float HEIGHT_SCALE = 0.35f/256.0f;
#include "MiniPatch.h" #include "MiniPatch.h"
#include "RenderableObject.h" #include "RenderableObject.h"
class CTerrain; class CTerrain;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// CPatch: a single terrain patch, PATCH_SIZE tiles square // CPatch: a single terrain patch, PATCH_SIZE tiles square

View File

@ -10,8 +10,8 @@
#ifndef _TERRAIN_H #ifndef _TERRAIN_H
#define _TERRAIN_H #define _TERRAIN_H
#include "Patch.h" #include "Patch.h"
#include "Vector3D.h" #include "Vector3D.h"
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// CTerrain: main terrain class; contains the heightmap describing elevation // CTerrain: main terrain class; contains the heightmap describing elevation

View File

@ -1,62 +1,64 @@
#include "ogl.h" #include "precompiled.h"
#include "res/tex.h"
#include "TextureEntry.h" #include "ogl.h"
#include "TextureManager.h" #include "res/tex.h"
#include "Texture.h" #include "TextureEntry.h"
#include "CLogger.h" #include "TextureManager.h"
#include "Renderer.h" #include "Texture.h"
#include "CLogger.h"
#include "Renderer.h"
/////////////////////////////////////////////////////////////////////////////////////
// CTextureEntry constructor
CTextureEntry::CTextureEntry(const char* name,int type) /////////////////////////////////////////////////////////////////////////////////////
: m_Name(name), m_Bitmap(0), m_Handle(0xffffffff), m_BaseColor(0), m_Type(type), m_BaseColorValid(false) // CTextureEntry constructor
{ CTextureEntry::CTextureEntry(const char* name,int type)
} : m_Name(name), m_Bitmap(0), m_Handle(0xffffffff), m_BaseColor(0), m_Type(type), m_BaseColorValid(false)
{
///////////////////////////////////////////////////////////////////////////////////// }
// LoadTexture: actually load the texture resource from file
void CTextureEntry::LoadTexture() /////////////////////////////////////////////////////////////////////////////////////
{ // LoadTexture: actually load the texture resource from file
CStr pathname("art/textures/terrain/types/"); void CTextureEntry::LoadTexture()
pathname+=g_TexMan.m_TerrainTextures[m_Type].m_Name; {
pathname+='/'; CStr pathname("art/textures/terrain/types/");
pathname+=m_Name; pathname+=g_TexMan.m_TerrainTextures[m_Type].m_Name;
pathname+='/';
CTexture texture; pathname+=m_Name;
texture.SetName(pathname);
if (g_Renderer.LoadTexture(&texture,GL_REPEAT)) { CTexture texture;
m_Handle=texture.GetHandle(); texture.SetName(pathname);
} else { if (g_Renderer.LoadTexture(&texture,GL_REPEAT)) {
m_Handle=0; m_Handle=texture.GetHandle();
} } else {
} m_Handle=0;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////// }
// BuildBaseColor: calculate the root color of the texture, used for coloring minimap, and store
// in m_BaseColor member ////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CTextureEntry::BuildBaseColor() // BuildBaseColor: calculate the root color of the texture, used for coloring minimap, and store
{ // in m_BaseColor member
Handle handle=GetHandle(); void CTextureEntry::BuildBaseColor()
g_Renderer.BindTexture(0,tex_id(handle)); {
Handle handle=GetHandle();
// get root color for coloring minimap by querying root level of the texture g_Renderer.BindTexture(0,tex_id(handle));
// (this should decompress any compressed textures for us),
// then scaling it down to a 1x1 size // get root color for coloring minimap by querying root level of the texture
// - an alternative approach of just grabbing the top level of the mipmap tree fails // (this should decompress any compressed textures for us),
// (or gives an incorrect colour) in some cases: // then scaling it down to a 1x1 size
// - suspect bug on Radeon cards when SGIS_generate_mipmap is used // - an alternative approach of just grabbing the top level of the mipmap tree fails
// - any textures without mipmaps // (or gives an incorrect colour) in some cases:
// we'll just take the basic approach here: // - suspect bug on Radeon cards when SGIS_generate_mipmap is used
int width,height; // - any textures without mipmaps
glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_WIDTH,&width); // we'll just take the basic approach here:
glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_HEIGHT,&height); int width,height;
glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_WIDTH,&width);
unsigned char* buf=new unsigned char[width*height*4]; glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_HEIGHT,&height);
glGetTexImage(GL_TEXTURE_2D,0,GL_BGRA_EXT,GL_UNSIGNED_BYTE,buf);
gluScaleImage(GL_BGRA_EXT,width,height,GL_UNSIGNED_BYTE,buf, unsigned char* buf=new unsigned char[width*height*4];
1,1,GL_UNSIGNED_BYTE,&m_BaseColor); glGetTexImage(GL_TEXTURE_2D,0,GL_BGRA_EXT,GL_UNSIGNED_BYTE,buf);
delete[] buf; gluScaleImage(GL_BGRA_EXT,width,height,GL_UNSIGNED_BYTE,buf,
1,1,GL_UNSIGNED_BYTE,&m_BaseColor);
m_BaseColorValid=true; delete[] buf;
m_BaseColorValid=true;
} }

View File

@ -3,51 +3,51 @@
#include "res/res.h" #include "res/res.h"
#include "CStr.h" #include "CStr.h"
////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////
// CTextureEntry: class wrapping a terrain texture object; contains various other required // CTextureEntry: class wrapping a terrain texture object; contains various other required
// elements - color of minimap, terrain "group" it belongs to, etc // elements - color of minimap, terrain "group" it belongs to, etc
class CTextureEntry class CTextureEntry
{ {
public: public:
CTextureEntry(const char* name,int type); CTextureEntry(const char* name,int type);
// accessor - return texture name // accessor - return texture name
const char* GetName() const { return (const char*) m_Name; } const char* GetName() const { return (const char*) m_Name; }
// accessor - get UI bitmap object // accessor - get UI bitmap object
void* GetBitmap() const { return m_Bitmap; } void* GetBitmap() const { return m_Bitmap; }
// accessor - set UI bitmap object // accessor - set UI bitmap object
void SetBitmap(void* bmp) { m_Bitmap=bmp; } void SetBitmap(void* bmp) { m_Bitmap=bmp; }
// accessor - get texture handle // accessor - get texture handle
Handle GetHandle() { Handle GetHandle() {
if (m_Handle==0xffffffff) LoadTexture(); if (m_Handle==0xffffffff) LoadTexture();
return m_Handle; return m_Handle;
} }
// accessor - get mipmap color // accessor - get mipmap color
u32 GetBaseColor() { u32 GetBaseColor() {
if (!m_BaseColorValid) BuildBaseColor(); if (!m_BaseColorValid) BuildBaseColor();
return m_BaseColor; return m_BaseColor;
} }
// accessor - return texture type // accessor - return texture type
int GetType() const { return m_Type; } int GetType() const { return m_Type; }
private: private:
// load texture from file // load texture from file
void LoadTexture(); void LoadTexture();
// calculate the root color of the texture, used for coloring minimap // calculate the root color of the texture, used for coloring minimap
void BuildBaseColor(); void BuildBaseColor();
// filename // filename
CStr m_Name; CStr m_Name;
// UI bitmap object // UI bitmap object
void* m_Bitmap; void* m_Bitmap;
// handle to GL texture data // handle to GL texture data
Handle m_Handle; Handle m_Handle;
// BGRA color of topmost mipmap level, for coloring minimap // BGRA color of topmost mipmap level, for coloring minimap
u32 m_BaseColor; u32 m_BaseColor;
// above color valid? // above color valid?
bool m_BaseColorValid; bool m_BaseColorValid;
// "type" of texture - index into TextureManager texturetypes array // "type" of texture - index into TextureManager texturetypes array
int m_Type; int m_Type;

View File

@ -68,13 +68,13 @@ CTextureEntry* CTextureManager::AddTexture(const char* filename,int type)
{ {
assert((uint)type<m_TerrainTextures.size()); assert((uint)type<m_TerrainTextures.size());
// create new texture entry // create new texture entry
CTextureEntry* texentry=new CTextureEntry(filename,type); CTextureEntry* texentry=new CTextureEntry(filename,type);
// add entry to list .. // add entry to list ..
m_TerrainTextures[type].m_Textures.push_back(texentry); m_TerrainTextures[type].m_Textures.push_back(texentry);
return texentry; return texentry;
} }
void CTextureManager::DeleteTexture(CTextureEntry* entry) void CTextureManager::DeleteTexture(CTextureEntry* entry)

View File

@ -18,6 +18,7 @@ void CRadioButton::HandleMessage(const SGUIMessage &Message)
switch (Message.type) switch (Message.type)
{ {
case GUIM_PRESSED: case GUIM_PRESSED:
{ // janwas added scoping to squelch ICC var decl warning
for (vector_pObjects::iterator it = GetParent()->ChildrenItBegin(); it != GetParent()->ChildrenItEnd(); ++it) for (vector_pObjects::iterator it = GetParent()->ChildrenItBegin(); it != GetParent()->ChildrenItEnd(); ++it)
{ {
// Notice, if you use other objects within the parent object that has got // Notice, if you use other objects within the parent object that has got
@ -30,6 +31,7 @@ void CRadioButton::HandleMessage(const SGUIMessage &Message)
//GetGUI()->TEMPmessage = "Check box " + string((const TCHAR*)m_Name) + " was " + (m_Settings.m_Checked?"checked":"unchecked"); //GetGUI()->TEMPmessage = "Check box " + string((const TCHAR*)m_Name) + " was " + (m_Settings.m_Checked?"checked":"unchecked");
break; break;
}
default: default:
break; break;

View File

@ -81,6 +81,25 @@ STMT(\
) )
#endif #endif
// useful because VC6 returns 0 on failure, instead of throwing.
// causes calling function to return a negative error code on failure.
#define SAFE_NEW(type, ptr)\
type* ptr;\
try\
{\
ptr = new type();\
}\
catch(std::bad_alloc)\
{\
ptr = 0;\
}\
if(!ptr)\
return ERR_NO_MEM;
enum LibError enum LibError
{ {
ERR_INVALID_HANDLE = -1000, ERR_INVALID_HANDLE = -1000,