runtime/blitz3d: Fixup C++ification

This commit is contained in:
Michael Fabian 'Xaymar' Dirks
2019-01-18 21:26:42 +01:00
parent 077776b704
commit 3afa84df85
71 changed files with 372 additions and 570 deletions
+3 -8
View File
@@ -5,7 +5,6 @@ add_library(${PROJECT_NAME} STATIC
"animation.hpp" "animation.hpp"
"animator.cpp" "animator.cpp"
"animator.hpp" "animator.hpp"
"blitz3d.hpp"
"brush.cpp" "brush.cpp"
"brush.hpp" "brush.hpp"
"cachedtexture.cpp" "cachedtexture.cpp"
@@ -61,8 +60,6 @@ add_library(${PROJECT_NAME} STATIC
"rendercontext.hpp" "rendercontext.hpp"
"sprite.cpp" "sprite.cpp"
"sprite.hpp" "sprite.hpp"
"std.cpp"
"std.hpp"
"surface.cpp" "surface.cpp"
"surface.hpp" "surface.hpp"
"terrain.cpp" "terrain.cpp"
@@ -76,11 +73,9 @@ add_library(${PROJECT_NAME} STATIC
) )
target_link_libraries(${PROJECT_NAME} target_link_libraries(${PROJECT_NAME}
PRIVATE config
config runtime_gfx
gxruntime stdutil
stdutil
PUBLIC
) )
target_include_directories(${PROJECT_NAME} target_include_directories(${PROJECT_NAME}
+2 -3
View File
@@ -1,11 +1,10 @@
#include "animation.hpp" #include "animation.hpp"
#include "std.hpp" #include <map>
struct Animation::Rep { struct Animation::Rep {
int ref_cnt; int ref_cnt;
typedef map<int, Quat> KeyList; typedef std::map<int, Quat> KeyList;
KeyList scale_anim, rot_anim, pos_anim; KeyList scale_anim, rot_anim, pos_anim;
+1 -8
View File
@@ -1,9 +1,4 @@
#pragma once
#ifndef ANIMATION_H
#define ANIMATION_H
#include <list>
#include "geom.hpp" #include "geom.hpp"
class Animation { class Animation {
@@ -33,5 +28,3 @@ class Animation {
Rep* write(); Rep* write();
}; };
#endif
+1 -3
View File
@@ -1,7 +1,5 @@
#include "animator.hpp" #include "animator.hpp"
#include "object.hpp" #include "object.hpp"
#include "std.hpp"
Animator::Animator(Animator* t) : _seqs(t->_seqs) Animator::Animator(Animator* t) : _seqs(t->_seqs)
{ {
@@ -24,7 +22,7 @@ Animator::Animator(Object* obj, int frames)
reset(); reset();
} }
Animator::Animator(const vector<Object*>& objs, int frames) : _objs(objs) Animator::Animator(const std::vector<Object*>& objs, int frames) : _objs(objs)
{ {
_anims.resize(_objs.size()); _anims.resize(_objs.size());
addSeq(frames); addSeq(frames);
+13 -17
View File
@@ -1,7 +1,5 @@
#pragma once
#ifndef ANIMATOR_H #include <vector>
#define ANIMATOR_H
#include "animation.hpp" #include "animation.hpp"
class Object; class Object;
@@ -14,7 +12,7 @@ class Animator {
Animator(Object* tree, int frames); Animator(Object* tree, int frames);
Animator(const vector<Object*>& objs, int frames); Animator(const std::vector<Object*>& objs, int frames);
void addSeq(int frames); void addSeq(int frames);
@@ -28,28 +26,28 @@ class Animator {
void update(float elapsed); void update(float elapsed);
int animSeq() const inline int animSeq() const
{ {
return _seq; return _seq;
} }
int animLen() const inline int animLen() const
{ {
return _seq_len; return _seq_len;
} }
float animTime() const inline float animTime() const
{ {
return _time; return _time;
} }
bool animating() const inline bool animating() const
{ {
return !!_mode; return !!_mode;
} }
int numSeqs() const inline int numSeqs() const
{ {
return _seqs.size(); return _seqs.size();
} }
const vector<Object*>& getObjects() const inline const std::vector<Object*>& getObjects() const
{ {
return _objs; return _objs;
} }
@@ -61,7 +59,7 @@ class Animator {
struct Anim { struct Anim {
//anim keys //anim keys
vector<Animation> keys; std::vector<Animation> keys;
//for transitions... //for transitions...
bool pos, scl, rot; bool pos, scl, rot;
Vector src_pos, dest_pos; Vector src_pos, dest_pos;
@@ -70,10 +68,10 @@ class Animator {
Anim() : pos(false), scl(false), rot(false) {} Anim() : pos(false), scl(false), rot(false) {}
}; };
vector<Seq> _seqs; std::vector<Seq> _seqs;
vector<Anim> _anims; std::vector<Anim> _anims;
vector<Object*> _objs; std::vector<Object*> _objs;
int _seq, _mode, _seq_len; int _seq, _mode, _seq_len;
float _time, _speed, _trans_time, _trans_speed; float _time, _speed, _trans_time, _trans_speed;
@@ -84,5 +82,3 @@ class Animator {
void beginTrans(); void beginTrans();
void updateTrans(); void updateTrans();
}; };
#endif
-5
View File
@@ -1,5 +0,0 @@
#ifndef BLITZ3D_H
#define BLITZ3D_H
#endif
+3 -3
View File
@@ -1,8 +1,8 @@
#include "brush.hpp" #include "brush.hpp"
#include "std.hpp"
#include "../gxruntime/gxgraphics.hpp" #include <gxgraphics.hpp>
#include <gxscene.hpp>
#include <gxcanvas.hpp>
struct Brush::Rep { struct Brush::Rep {
union { union {
+3 -6
View File
@@ -1,10 +1,9 @@
#pragma once
#ifndef BRUSH_H
#define BRUSH_H
#include "geom.hpp" #include "geom.hpp"
#include "texture.hpp" #include "texture.hpp"
#include <gxscene.hpp>
class Brush { class Brush {
public: public:
Brush(); Brush();
@@ -38,5 +37,3 @@ class Brush {
Rep* write() const; Rep* write() const;
}; };
#endif
+28 -28
View File
@@ -1,23 +1,25 @@
#include "cachedtexture.hpp" #include "cachedtexture.hpp"
#include "std.hpp"
#include <stdutil.hpp>
#include <gxcanvas.hpp>
#include <gxgraphics.hpp>
int active_texs; int active_texs;
extern gxRuntime* gx_runtime; extern gxRuntime* gx_runtime;
extern gxGraphics* gx_graphics; extern gxGraphics* gx_graphics;
set<CachedTextureFactory::CachedTexture*> CachedTextureFactory::rep_set; std::set<CachedTexture::CTInstance*> CachedTexture::rep_set;
static string path; static std::string path;
struct CachedTextureFactory::CachedTexture { struct CachedTexture::CTInstance {
int ref_cnt; int ref_cnt;
string file; std::string file;
int flags, w, h, first; int flags, w, h, first;
vector<gxCanvas*> frames; std::vector<gxCanvas*> frames;
CachedTexture(int w, int h, int flags, int cnt) : ref_cnt(1), flags(flags), w(w), h(h), first(0) CTInstance(int w, int h, int flags, int cnt) : ref_cnt(1), flags(flags), w(w), h(h), first(0)
{ {
++active_texs; ++active_texs;
while (cnt-- > 0) { while (cnt-- > 0) {
@@ -28,7 +30,7 @@ struct CachedTextureFactory::CachedTexture {
} }
} }
CachedTexture(const string& f, int flags, int w, int h, int first, int cnt) CTInstance(const std::string& f, int flags, int w, int h, int first, int cnt)
: ref_cnt(1), file(f), flags(flags), w(w), h(h), first(first) : ref_cnt(1), file(f), flags(flags), w(w), h(h), first(first)
{ {
++active_texs; ++active_texs;
@@ -94,7 +96,7 @@ struct CachedTextureFactory::CachedTexture {
gx_graphics->freeCanvas(t); gx_graphics->freeCanvas(t);
} }
~CachedTexture() ~CTInstance()
{ {
--active_texs; --active_texs;
for (int k = 0; k < frames.size(); ++k) for (int k = 0; k < frames.size(); ++k)
@@ -102,12 +104,11 @@ struct CachedTextureFactory::CachedTexture {
} }
}; };
CachedTextureFactory::CachedTexture* CachedTextureFactory::findRep(const string& f, int flags, int w, int h, int first, CachedTexture::CTInstance* CachedTexture::findRep(const std::string& f, int flags, int w, int h, int first, int cnt)
int cnt)
{ {
set<CachedTexture*>::const_iterator it; std::set<CTInstance*>::const_iterator it;
for (it = rep_set.begin(); it != rep_set.end(); ++it) { for (it = rep_set.begin(); it != rep_set.end(); ++it) {
CachedTexture* rep = *it; CTInstance* rep = *it;
if (rep->file == f && rep->flags == flags && rep->w == w && rep->h == h && rep->first == first if (rep->file == f && rep->flags == flags && rep->w == w && rep->h == h && rep->first == first
&& rep->frames.size() == cnt) { && rep->frames.size() == cnt) {
++rep->ref_cnt; ++rep->ref_cnt;
@@ -117,38 +118,37 @@ CachedTextureFactory::CachedTexture* CachedTextureFactory::findRep(const string&
return 0; return 0;
} }
CachedTextureFactory::CachedTextureFactory(int w, int h, int flags, int cnt) : rep(new CachedTexture(w, h, flags, cnt)) CachedTexture::CachedTexture(int w, int h, int flags, int cnt) : rep(new CTInstance(w, h, flags, cnt)) {}
{}
CachedTextureFactory::CachedTextureFactory(const string& f_, int flags, int w, int h, int first, int cnt) CachedTexture::CachedTexture(const std::string& f_, int flags, int w, int h, int first, int cnt)
{ {
string f = f_; std::string f = f_;
if (f.substr(0, 2) == ".\\") if (f.substr(0, 2) == ".\\")
f = f.substr(2); f = f.substr(2);
if (path.size()) { if (path.size()) {
string t = path + tolower(filenamefile(f)); std::string t = path + tolower(filenamefile(f));
if (rep = findRep(t, flags, w, h, first, cnt)) if (rep = findRep(t, flags, w, h, first, cnt))
return; return;
rep = new CachedTexture(t, flags, w, h, first, cnt); rep = new CTInstance(t, flags, w, h, first, cnt);
if (rep->frames.size()) { if (rep->frames.size()) {
rep_set.insert(rep); rep_set.insert(rep);
return; return;
} }
delete rep; delete rep;
} }
string t = tolower(fullfilename(f)); std::string t = tolower(fullfilename(f));
if (rep = findRep(t, flags, w, h, first, cnt)) if (rep = findRep(t, flags, w, h, first, cnt))
return; return;
rep = new CachedTexture(t, flags, w, h, first, cnt); rep = new CTInstance(t, flags, w, h, first, cnt);
rep_set.insert(rep); rep_set.insert(rep);
} }
CachedTextureFactory::CachedTextureFactory(const CachedTextureFactory& t) : rep(t.rep) CachedTexture::CachedTexture(const CachedTexture& t) : rep(t.rep)
{ {
++rep->ref_cnt; ++rep->ref_cnt;
} }
CachedTextureFactory::~CachedTextureFactory() CachedTexture::~CachedTexture()
{ {
if (!--rep->ref_cnt) { if (!--rep->ref_cnt) {
rep_set.erase(rep); rep_set.erase(rep);
@@ -156,7 +156,7 @@ CachedTextureFactory::~CachedTextureFactory()
} }
} }
CachedTextureFactory& CachedTextureFactory::operator=(const CachedTextureFactory& t) CachedTexture& CachedTexture::operator=(const CachedTexture& t)
{ {
++t.rep->ref_cnt; ++t.rep->ref_cnt;
if (!--rep->ref_cnt) { if (!--rep->ref_cnt) {
@@ -167,17 +167,17 @@ CachedTextureFactory& CachedTextureFactory::operator=(const CachedTextureFactory
return *this; return *this;
} }
string CachedTextureFactory::getName() const std::string CachedTexture::getName() const
{ {
return rep->file; return rep->file;
} }
const vector<gxCanvas*>& CachedTextureFactory::getFrames() const const std::vector<gxCanvas*>& CachedTexture::getFrames() const
{ {
return rep->frames; return rep->frames;
} }
void CachedTextureFactory::setPath(const string& t) void CachedTexture::setPath(const std::string& t)
{ {
path = tolower(t); path = tolower(t);
if (int sz = path.size()) { if (int sz = path.size()) {
+19 -20
View File
@@ -1,36 +1,35 @@
#pragma once
#include <set>
#include <string>
#include <vector>
#ifndef CACHEDTEXTURE_H class gxCanvas;
#define CACHEDTEXTURE_H
#include "gxcanvas.hpp" class CachedTexture {
class CachedTextureFactory {
public: public:
CachedTextureFactory(int w, int h, int flags, int cnt); CachedTexture(int w, int h, int flags, int cnt);
CachedTextureFactory(const string& f, int flags, int w, int h, int first, int cnt); CachedTexture(const std::string& f, int flags, int w, int h, int first, int cnt);
CachedTextureFactory(const CachedTextureFactory& t); CachedTexture(const CachedTexture& t);
~CachedTextureFactory(); ~CachedTexture();
CachedTextureFactory& operator=(const CachedTextureFactory& t); CachedTexture& operator=(const CachedTexture& t);
string getName() const; std::string getName() const;
const vector<gxCanvas*>& getFrames() const; const std::vector<gxCanvas*>& getFrames() const;
bool operator<(const CachedTextureFactory& t) const bool operator<(const CachedTexture& t) const
{ {
return rep < t.rep; return rep < t.rep;
} }
static void setPath(const string& t); static void setPath(const std::string& t);
private: private:
struct CachedTexture; struct CTInstance;
CachedTexture* rep; CTInstance* rep;
CachedTexture* findRep(const string& f, int flags, int w, int h, int first, int cnt); CTInstance* findRep(const std::string& f, int flags, int w, int h, int first, int cnt);
static set<CachedTexture*> rep_set; static std::set<CTInstance*> rep_set;
}; };
#endif
+2 -2
View File
@@ -1,6 +1,6 @@
#include "camera.hpp" #include "camera.hpp"
#include "std.hpp"
#include <gxscene.hpp>
extern gxScene* gx_scene; extern gxScene* gx_scene;
+1 -6
View File
@@ -1,7 +1,4 @@
#pragma once
#ifndef CAMERA_H
#define CAMERA_H
#include "frustum.hpp" #include "frustum.hpp"
#include "mirror.hpp" #include "mirror.hpp"
#include "model.hpp" #include "model.hpp"
@@ -56,5 +53,3 @@ class Camera : public Object {
mutable Frustum local_frustum; mutable Frustum local_frustum;
mutable bool local_valid; mutable bool local_valid;
}; };
#endif
+2 -2
View File
@@ -1,6 +1,6 @@
#include "collision.hpp" #include "collision.hpp"
#include "std.hpp"
#include <gxruntime.hpp>
const float COLLISION_FLT_EPSILON = .001f; const float COLLISION_FLT_EPSILON = .001f;
+1 -6
View File
@@ -1,7 +1,4 @@
#pragma once
#ifndef COLLISION_H
#define COLLISION_H
#include "geom.hpp" #include "geom.hpp"
extern const float COLLISION_FLT_EPSILON; extern const float COLLISION_FLT_EPSILON;
@@ -23,5 +20,3 @@ struct Collision {
bool boxCollide(const Line& src_line, float src_radius, const Box& box); bool boxCollide(const Line& src_line, float src_radius, const Box& box);
}; };
#endif
+1 -5
View File
@@ -1,8 +1,4 @@
#include "entity.hpp" #include "entity.hpp"
#include "std.hpp"
//#include "stats.hpp"
Entity *Entity::_orphans, *Entity::_last_orphan; Entity *Entity::_orphans, *Entity::_last_orphan;
@@ -119,7 +115,7 @@ void Entity::SetParent(Entity* p)
InvalidateWorldTransform(); InvalidateWorldTransform();
} }
void Entity::SetName(const string& t) void Entity::SetName(const std::string& t)
{ {
m_name = t; m_name = t;
} }
+1 -7
View File
@@ -1,9 +1,5 @@
#pragma once
#ifndef ENTITY_H
#define ENTITY_H
#include <list> #include <list>
#include "geom.hpp" #include "geom.hpp"
class Entity; class Entity;
@@ -132,5 +128,3 @@ class Entity {
void invalidateLocal(); void invalidateLocal();
void InvalidateWorldTransform(); void InvalidateWorldTransform();
}; };
#endif
-2
View File
@@ -1,6 +1,4 @@
#include "frustum.hpp" #include "frustum.hpp"
#include "std.hpp"
Frustum::Frustum() {} Frustum::Frustum() {}
+1 -6
View File
@@ -1,7 +1,4 @@
#pragma once
#ifndef FRUSTUM_H
#define FRUSTUM_H
#include "geom.hpp" #include "geom.hpp"
class Frustum { class Frustum {
@@ -39,5 +36,3 @@ class Frustum {
Vector verts[9]; Vector verts[9];
void makePlanes(); void makePlanes();
}; };
#endif
-2
View File
@@ -1,6 +1,4 @@
#include "geom.hpp" #include "geom.hpp"
#include "std.hpp"
Matrix Matrix::tmps[64]; Matrix Matrix::tmps[64];
Transform Transform::tmps[64]; Transform Transform::tmps[64];
+3 -7
View File
@@ -1,8 +1,6 @@
#pragma once
#ifndef GEOM_H #include <cmath>
#define GEOM_H #include <cfloat>
#include <math.h>
class Vector; class Vector;
class Line; class Line;
@@ -738,5 +736,3 @@ inline Quat matrixQuat(const Matrix& p)
} }
return Quat(w, Vector(x, y, z)); return Quat(w, Vector(x, y, z));
} }
#endif
+3 -3
View File
@@ -1,7 +1,7 @@
#include "light.hpp" #include "light.hpp"
#include "../gxruntime/gxscene.hpp"
#include "std.hpp" #include <gxscene.hpp>
#include <gxlight.hpp>
extern gxScene* gx_scene; extern gxScene* gx_scene;
+2 -7
View File
@@ -1,12 +1,9 @@
#pragma once
#ifndef LIGHT_H
#define LIGHT_H
#include "geom.hpp" #include "geom.hpp"
#include "gxlight.hpp"
#include "object.hpp" #include "object.hpp"
class World; class World;
class gxLight;
class Light : public Object { class Light : public Object {
public: public:
@@ -33,5 +30,3 @@ class Light : public Object {
friend class World; friend class World;
gxLight* light; gxLight* light;
}; };
#endif
+2 -2
View File
@@ -1,6 +1,6 @@
#include "listener.hpp" #include "listener.hpp"
#include "std.hpp"
#include <gxaudio.hpp>
extern gxAudio* gx_audio; extern gxAudio* gx_audio;
+1 -6
View File
@@ -1,7 +1,4 @@
#pragma once
#ifndef LISTENER_H
#define LISTENER_H
#include "object.hpp" #include "object.hpp"
class Listener : public Object { class Listener : public Object {
@@ -25,5 +22,3 @@ class Listener : public Object {
private: private:
}; };
#endif
+27 -25
View File
@@ -1,8 +1,10 @@
#include "loader_3ds.hpp" #include "loader_3ds.hpp"
#include "animation.hpp" #include "animation.hpp"
#include "meshmodel.hpp" #include "meshmodel.hpp"
#include "std.hpp" #include "animator.hpp"
#include <fstream>
#include <gxruntime.hpp>
extern gxRuntime* gx_runtime; extern gxRuntime* gx_runtime;
@@ -14,9 +16,9 @@ extern gxRuntime* gx_runtime;
class Box; class Box;
static filebuf in; static std::filebuf in;
static int chunk_end; static int chunk_end;
static vector<int> parent_end; static std::vector<int> parent_end;
static unsigned short anim_len; static unsigned short anim_len;
static bool conv, flip_tris; static bool conv, flip_tris;
@@ -28,30 +30,30 @@ struct Face3DS {
Brush brush; Brush brush;
}; };
static vector<Face3DS> faces; static std::vector<Face3DS> faces;
//static vector<Surface::Vertex> vertices; //static vector<Surface::Vertex> vertices;
static map<string, Brush> materials_map; static std::map<std::string, Brush> materials_map;
static map<string, MeshModel*> name_map; static std::map<std::string, MeshModel*> name_map;
static map<int, MeshModel*> id_map; static std::map<int, MeshModel*> id_map;
static int nextChunk() static int nextChunk()
{ {
in.pubseekoff(chunk_end, ios_base::beg); in.pubseekoff(chunk_end, std::ios_base::beg);
if (chunk_end == parent_end.back()) if (chunk_end == parent_end.back())
return 0; return 0;
unsigned short id; unsigned short id;
int len; int len;
in.sgetn((char*)&id, 2); in.sgetn((char*)&id, 2);
in.sgetn((char*)&len, 4); in.sgetn((char*)&len, 4);
chunk_end = (int)in.pubseekoff(0, ios_base::cur) + len - 6; chunk_end = (int)in.pubseekoff(0, std::ios_base::cur) + len - 6;
return id; return id;
} }
static void enterChunk() static void enterChunk()
{ {
parent_end.push_back(chunk_end); parent_end.push_back(chunk_end);
chunk_end = (int)in.pubseekoff(0, ios_base::cur); chunk_end = (int)in.pubseekoff(0, std::ios_base::cur);
} }
static void leaveChunk() static void leaveChunk()
@@ -60,9 +62,9 @@ static void leaveChunk()
parent_end.pop_back(); parent_end.pop_back();
} }
static string parseString() static std::string parseString()
{ {
string t; std::string t;
while (int c = in.sbumpc()) while (int c = in.sbumpc())
t += char(c); t += char(c);
return t; return t;
@@ -137,7 +139,7 @@ static void parseVertList()
static void parseFaceMat() static void parseFaceMat()
{ {
string name = parseString(); std::string name = parseString();
_log("FaceMat: " + name); _log("FaceMat: " + name);
Brush mat = materials_map[name]; Brush mat = materials_map[name];
unsigned short cnt; unsigned short cnt;
@@ -256,7 +258,7 @@ static void parseTriMesh(MeshModel* mesh)
static void parseObject(MeshModel* root) static void parseObject(MeshModel* root)
{ {
//skip name //skip name
string name = parseString(); std::string name = parseString();
_log("Object:" + name); _log("Object:" + name);
MeshModel* mesh = 0; MeshModel* mesh = 0;
@@ -279,7 +281,7 @@ static void parseMaterial()
{ {
_log("Material"); _log("Material");
Brush mat; Brush mat;
string name, tex_name; std::string name, tex_name;
enterChunk(); enterChunk();
while (int id = nextChunk()) { while (int id = nextChunk()) {
switch (id) { switch (id) {
@@ -339,9 +341,9 @@ static void parseAnimKeys(Animation* anim, int type)
int cnt = 0; int cnt = 0;
short t_flags; short t_flags;
in.sgetn((char*)&t_flags, 2); in.sgetn((char*)&t_flags, 2);
in.pubseekoff(8, ios_base::cur); in.pubseekoff(8, std::ios_base::cur);
in.sgetn((char*)&cnt, 2); in.sgetn((char*)&cnt, 2);
in.pubseekoff(2, ios_base::cur); in.pubseekoff(2, std::ios_base::cur);
_log("ANIM_TRACK: frames=" + itoa(cnt)); _log("ANIM_TRACK: frames=" + itoa(cnt));
Vector pos, axis, scale; Vector pos, axis, scale;
float angle; float angle;
@@ -403,7 +405,7 @@ static void parseMeshInfo(MeshModel* root, float curr_time)
{ {
_log("OBJECT_NODE_TAG"); _log("OBJECT_NODE_TAG");
enterChunk(); enterChunk();
string name, inst; std::string name, inst;
Vector pivot; Vector pivot;
Animation anim; Animation anim;
unsigned short id = 65535, parent = 65535, flags1, flags2; unsigned short id = 65535, parent = 65535, flags1, flags2;
@@ -453,7 +455,7 @@ static void parseMeshInfo(MeshModel* root, float curr_time)
MeshModel* p = root; MeshModel* p = root;
if (parent != 65535) { if (parent != 65535) {
map<int, MeshModel*>::const_iterator it = id_map.find(parent); std::map<int, MeshModel*>::const_iterator it = id_map.find(parent);
if (it == id_map.end()) if (it == id_map.end())
return; return;
p = it->second; p = it->second;
@@ -464,7 +466,7 @@ static void parseMeshInfo(MeshModel* root, float curr_time)
mesh->SetName(inst); mesh->SetName(inst);
mesh->SetParent(p); mesh->SetParent(p);
} else { } else {
map<string, MeshModel*>::const_iterator it = name_map.find(name); std::map<std::string, MeshModel*>::const_iterator it = name_map.find(name);
if (it == name_map.end()) if (it == name_map.end())
return; return;
mesh = it->second; mesh = it->second;
@@ -487,7 +489,7 @@ static void parseKeyFramer(MeshModel* root)
{ {
_log("KeyFramer"); _log("KeyFramer");
enterChunk(); enterChunk();
string file_3ds; std::string file_3ds;
unsigned short rev, curr_time = 0; unsigned short rev, curr_time = 0;
while (int id = nextChunk()) { while (int id = nextChunk()) {
switch (id) { switch (id) {
@@ -522,7 +524,7 @@ static MeshModel* parseFile()
in.sgetn((char*)&len, 4); in.sgetn((char*)&len, 4);
if (id != CHUNK_MAIN) if (id != CHUNK_MAIN)
return 0; return 0;
chunk_end = (int)in.pubseekoff(0, ios_base::cur) + len - 6; chunk_end = (int)in.pubseekoff(0, std::ios_base::cur) + len - 6;
enterChunk(); enterChunk();
MeshModel* root = new MeshModel(); MeshModel* root = new MeshModel();
@@ -540,7 +542,7 @@ static MeshModel* parseFile()
return root; return root;
} }
MeshModel* Loader_3DS::load(const string& filename, const Transform& t, int hint) MeshModel* Loader_3DS::load(const std::string& filename, const Transform& t, int hint)
{ {
conv_tform = t; conv_tform = t;
conv = flip_tris = false; conv = flip_tris = false;
@@ -553,7 +555,7 @@ MeshModel* Loader_3DS::load(const string& filename, const Transform& t, int hint
collapse = !!(hint & MeshLoader::HINT_COLLAPSE); collapse = !!(hint & MeshLoader::HINT_COLLAPSE);
animonly = !!(hint & MeshLoader::HINT_ANIMONLY); animonly = !!(hint & MeshLoader::HINT_ANIMONLY);
if (!in.open(filename.c_str(), ios_base::in | ios_base::binary)) { if (!in.open(filename.c_str(), std::ios_base::in | std::ios_base::binary)) {
return 0; return 0;
} }
+2 -7
View File
@@ -1,12 +1,7 @@
#pragma once
#ifndef LOADER_3DS_H
#define LOADER_3DS_H
#include "meshloader.hpp" #include "meshloader.hpp"
class Loader_3DS : public MeshLoader { class Loader_3DS : public MeshLoader {
public: public:
MeshModel* load(const string& f, const Transform& conv, int hint); MeshModel* load(const std::string& f, const Transform& conv, int hint);
}; };
#endif
+11 -12
View File
@@ -1,17 +1,16 @@
#include "loader_b3d.hpp" #include "loader_b3d.hpp"
#include "meshmodel.hpp" #include "meshmodel.hpp"
#include "meshutil.hpp" #include "meshutil.hpp"
#include "pivot.hpp" #include "pivot.hpp"
#include "std.hpp" #include "animator.hpp"
//#define SHOW_BONES //#define SHOW_BONES
static FILE* in; static FILE* in;
static vector<int> chunk_stack; static std::vector<int> chunk_stack;
static vector<Texture> textures; static std::vector<Texture> textures;
static vector<Brush> brushes; static std::vector<Brush> brushes;
static vector<Object*> bones; static std::vector<Object*> bones;
static bool collapse; static bool collapse;
static bool animonly; static bool animonly;
@@ -108,9 +107,9 @@ static void readColor(unsigned* t)
*t = (int(a * 255) << 24) | (int(r * 255) << 16) | (int(g * 255) << 8) | int(b * 255); *t = (int(a * 255) << 24) | (int(r * 255) << 16) | (int(g * 255) << 8) | int(b * 255);
} }
static string readString() static std::string readString()
{ {
string t; std::string t;
for (;;) { for (;;) {
char c; char c;
read(&c, 1); read(&c, 1);
@@ -123,7 +122,7 @@ static string readString()
static void readTextures() static void readTextures()
{ {
while (chunkSize()) { while (chunkSize()) {
string name = readString(); std::string name = readString();
int flags = readInt(); int flags = readInt();
int blend = readInt(); int blend = readInt();
float pos[2], scl[2]; float pos[2], scl[2];
@@ -156,7 +155,7 @@ static void readBrushes()
int tex_id[8] = {-1, -1, -1, -1, -1, -1, -1, -1}; int tex_id[8] = {-1, -1, -1, -1, -1, -1, -1, -1};
while (chunkSize()) { while (chunkSize()) {
string name = readString(); std::string name = readString();
float col[4]; float col[4];
readFloatArray(col, 4); readFloatArray(col, 4);
float shi = readFloat(); float shi = readFloat();
@@ -291,7 +290,7 @@ static Object* readObject(Object* parent)
{ {
Object* obj = 0; Object* obj = 0;
string name = readString(); std::string name = readString();
float pos[3], scl[3], rot[4]; float pos[3], scl[3], rot[4];
readFloatArray(pos, 3); readFloatArray(pos, 3);
readFloatArray(scl, 3); readFloatArray(scl, 3);
@@ -362,7 +361,7 @@ static Object* readObject(Object* parent)
return obj; return obj;
} }
MeshModel* Loader_B3D::load(const string& f, const Transform& conv, int hint) MeshModel* Loader_B3D::load(const std::string& f, const Transform& conv, int hint)
{ {
collapse = !!(hint & MeshLoader::HINT_COLLAPSE); collapse = !!(hint & MeshLoader::HINT_COLLAPSE);
animonly = !!(hint & MeshLoader::HINT_ANIMONLY); animonly = !!(hint & MeshLoader::HINT_ANIMONLY);
+3 -7
View File
@@ -1,12 +1,8 @@
#pragma once
#ifndef LOADER_B3D_H
#define LOADER_B3D_H
#include "meshloader.hpp" #include "meshloader.hpp"
#include <string>
class Loader_B3D : public MeshLoader { class Loader_B3D : public MeshLoader {
public: public:
MeshModel* load(const string& f, const Transform& conv, int hint); MeshModel* load(const std::string& f, const Transform& conv, int hint);
}; };
#endif
+3 -4
View File
@@ -1,15 +1,14 @@
#include "md2model.hpp" #include "md2model.hpp"
#include "md2rep.hpp" #include "md2rep.hpp"
#include "std.hpp" #include "animator.hpp"
struct MD2Model::Rep : public MD2Rep { struct MD2Model::Rep : public MD2Rep {
int ref_cnt; int ref_cnt;
Rep(const string& f) : MD2Rep(f), ref_cnt(1) {} Rep(const std::string& f) : MD2Rep(f), ref_cnt(1) {}
}; };
MD2Model::MD2Model(const string& f) MD2Model::MD2Model(const std::string& f)
: rep(new Rep(f)), anim_mode(0), anim_time(0), render_a(0), render_b(0), render_t(0), trans_verts(0) : rep(new Rep(f)), anim_mode(0), anim_time(0), render_a(0), render_b(0), render_t(0), trans_verts(0)
{} {}
+3 -7
View File
@@ -1,13 +1,11 @@
#pragma once
#ifndef MD2MODEL_H
#define MD2MODEL_H
#include "md2rep.hpp" #include "md2rep.hpp"
#include "model.hpp" #include "model.hpp"
#include <string>
class MD2Model : public Model { class MD2Model : public Model {
public: public:
MD2Model(const string& filename); MD2Model(const std::string& filename);
MD2Model(const MD2Model& t); MD2Model(const MD2Model& t);
~MD2Model(); ~MD2Model();
@@ -59,5 +57,3 @@ class MD2Model : public Model {
//Unimplemented //Unimplemented
MD2Model& operator=(const MD2Model&); MD2Model& operator=(const MD2Model&);
}; };
#endif
-2
View File
@@ -1,6 +1,4 @@
#include "md2norms.hpp" #include "md2norms.hpp"
#include "std.hpp"
float md2norms[162][3] = { float md2norms[162][3] = {
{-0.525731f, 0.000000f, 0.850651f}, {-0.442863f, 0.238856f, 0.864188f}, {-0.295242f, 0.000000f, 0.955423f}, {-0.525731f, 0.000000f, 0.850651f}, {-0.442863f, 0.238856f, 0.864188f}, {-0.295242f, 0.000000f, 0.955423f},
+1 -6
View File
@@ -1,7 +1,2 @@
#pragma once
#ifndef MD2NORMS_H
#define MD2NORMS_H
extern float md2norms[162][3]; extern float md2norms[162][3];
#endif
+14 -12
View File
@@ -1,7 +1,9 @@
#include "md2rep.hpp" #include "md2rep.hpp"
#include "md2norms.hpp" #include "md2norms.hpp"
#include "std.hpp" #include <fstream>
#include <gxruntime.hpp>
#include <gxgraphics.hpp>
extern gxRuntime* gx_runtime; extern gxRuntime* gx_runtime;
extern gxGraphics* gx_graphics; extern gxGraphics* gx_graphics;
@@ -57,12 +59,12 @@ struct t_tri {
unsigned short verts[3]; unsigned short verts[3];
}; };
MD2Rep::MD2Rep(const string& f) : mesh(0), n_verts(0), n_tris(0), n_frames(0) MD2Rep::MD2Rep(const std::string& f) : mesh(0), n_verts(0), n_tris(0), n_frames(0)
{ {
filebuf in; std::filebuf in;
md2_header header; md2_header header;
if (!in.open(f.c_str(), ios_base::in | ios_base::binary)) if (!in.open(f.c_str(), std::ios_base::in | std::ios_base::binary))
return; return;
if (in.sgetn((char*)&header, sizeof(header)) != sizeof(header)) if (in.sgetn((char*)&header, sizeof(header)) != sizeof(header))
return; return;
@@ -73,20 +75,20 @@ MD2Rep::MD2Rep(const string& f) : mesh(0), n_verts(0), n_tris(0), n_frames(0)
n_tris = header.numTriangles; n_tris = header.numTriangles;
//read in tex coords //read in tex coords
vector<md2_uv> md2_uvs; std::vector<md2_uv> md2_uvs;
md2_uvs.resize(header.numTexCoords); md2_uvs.resize(header.numTexCoords);
in.pubseekpos(header.offsetTexCoords); in.pubseekpos(header.offsetTexCoords);
in.sgetn((char*)(&md2_uvs.begin()[0]), header.numTexCoords * sizeof(md2_uv)); in.sgetn((char*)(&md2_uvs.begin()[0]), header.numTexCoords * sizeof(md2_uv));
//read in triangles //read in triangles
vector<md2_tri> md2_tris; std::vector<md2_tri> md2_tris;
md2_tris.resize(n_tris); md2_tris.resize(n_tris);
in.pubseekpos(header.offsetTriangles); in.pubseekpos(header.offsetTriangles);
in.sgetn((char*)(&md2_tris.begin()[0]), n_tris * sizeof(md2_tri)); in.sgetn((char*)(&md2_tris.begin()[0]), n_tris * sizeof(md2_tri));
vector<t_tri> t_tris; std::vector<t_tri> t_tris;
vector<t_vert> t_verts; std::vector<t_vert> t_verts;
map<t_vert, int> t_map; std::map<t_vert, int> t_map;
int k; int k;
for (k = 0; k < n_tris; ++k) { for (k = 0; k < n_tris; ++k) {
@@ -95,7 +97,7 @@ MD2Rep::MD2Rep(const string& f) : mesh(0), n_verts(0), n_tris(0), n_frames(0)
t_vert t; t_vert t;
t.i = md2_tris[k].verts[j]; t.i = md2_tris[k].verts[j];
t.uv = md2_tris[k].uvs[j]; t.uv = md2_tris[k].uvs[j];
map<t_vert, int>::iterator it = t_map.find(t); std::map<t_vert, int>::iterator it = t_map.find(t);
if (it == t_map.end()) { if (it == t_map.end()) {
//create new vert //create new vert
tr.verts[j] = t_map[t] = t_verts.size(); tr.verts[j] = t_map[t] = t_verts.size();
@@ -117,7 +119,7 @@ MD2Rep::MD2Rep(const string& f) : mesh(0), n_verts(0), n_tris(0), n_frames(0)
frames.resize(n_frames); frames.resize(n_frames);
in.pubseekpos(header.offsetFrames); in.pubseekpos(header.offsetFrames);
vector<md2_vert> md2_verts; std::vector<md2_vert> md2_verts;
md2_verts.resize(header.numVertices); md2_verts.resize(header.numVertices);
//read in frames //read in frames
+7 -10
View File
@@ -1,8 +1,7 @@
#pragma once
#ifndef MD2REP_H
#define MD2REP_H
#include "model.hpp" #include "model.hpp"
#include <string>
#include <vector>
class MD2Rep { class MD2Rep {
public: public:
@@ -10,7 +9,7 @@ class MD2Rep {
Vector coords, normal; Vector coords, normal;
}; };
MD2Rep(const string& f); MD2Rep(const std::string& f);
virtual ~MD2Rep(); virtual ~MD2Rep();
void render(Vert* verts, int frame); void render(Vert* verts, int frame);
@@ -46,15 +45,13 @@ class MD2Rep {
struct Frame { struct Frame {
Vector scale, trans; Vector scale, trans;
vector<Vertex> verts; std::vector<Vertex> verts;
}; };
Box box; Box box;
gxMesh* mesh; gxMesh* mesh;
int n_frames; int n_frames;
int n_verts, n_tris; int n_verts, n_tris;
vector<Frame> frames; std::vector<Frame> frames;
vector<VertexUV> uvs; std::vector<VertexUV> uvs;
}; };
#endif
+14 -12
View File
@@ -1,9 +1,10 @@
#include "meshcollider.hpp" #include "meshcollider.hpp"
#include "std.hpp" #include <map>
#include <gxruntime.hpp>
static const int MAX_COLL_TRIS = 16; static const int MAX_COLL_TRIS = 16;
static vector<Vector> tri_centres; static std::vector<Vector> tri_centres;
extern float stats3d[10]; extern float stats3d[10];
@@ -47,9 +48,10 @@ static bool trisIntersect(const Vector a[3], const Vector b[3])
return triTest(a, b) || triTest(b, a); return triTest(a, b) || triTest(b, a);
} }
MeshCollider::MeshCollider(const vector<Vertex>& verts, const vector<Triangle>& tris) : vertices(verts), triangles(tris) MeshCollider::MeshCollider(const std::vector<Vertex>& verts, const std::vector<Triangle>& tris)
: vertices(verts), triangles(tris)
{ {
vector<int> ts; std::vector<int> ts;
tri_centres.clear(); tri_centres.clear();
for (int k = 0; k < triangles.size(); ++k) { for (int k = 0; k < triangles.size(); ++k) {
const MeshCollider::Triangle& t = triangles[k]; const MeshCollider::Triangle& t = triangles[k];
@@ -122,7 +124,7 @@ bool MeshCollider::collide(const Box& line_box, const Line& line, float radius,
return hit; return hit;
} }
Box MeshCollider::nodeBox(const vector<int>& tris) Box MeshCollider::nodeBox(const std::vector<int>& tris)
{ {
Box box; Box box;
for (int k = 0; k < tris.size(); ++k) { for (int k = 0; k < tris.size(); ++k) {
@@ -133,7 +135,7 @@ Box MeshCollider::nodeBox(const vector<int>& tris)
return box; return box;
} }
MeshCollider::Node* MeshCollider::createLeaf(const vector<int>& tris) MeshCollider::Node* MeshCollider::createLeaf(const std::vector<int>& tris)
{ {
Node* c = new Node; Node* c = new Node;
c->box = nodeBox(tris); c->box = nodeBox(tris);
@@ -142,7 +144,7 @@ MeshCollider::Node* MeshCollider::createLeaf(const vector<int>& tris)
return c; return c;
} }
MeshCollider::Node* MeshCollider::createNode(const vector<int>& tris) MeshCollider::Node* MeshCollider::createNode(const std::vector<int>& tris)
{ {
if (tris.size() <= MAX_COLL_TRIS) if (tris.size() <= MAX_COLL_TRIS)
return createLeaf(tris); return createLeaf(tris);
@@ -166,16 +168,16 @@ MeshCollider::Node* MeshCollider::createNode(const vector<int>& tris)
//sort by axis //sort by axis
// //
int k; int k;
multimap<float, int> axis_map; std::multimap<float, int> axis_map;
for (k = 0; k < tris.size(); ++k) { for (k = 0; k < tris.size(); ++k) {
pair<float, int> p(tri_centres[tris[k]][axis], tris[k]); std::pair<float, int> p(tri_centres[tris[k]][axis], tris[k]);
axis_map.insert(p); axis_map.insert(p);
} }
//generate left node //generate left node
// //
vector<int> new_tris; std::vector<int> new_tris;
multimap<float, int>::iterator it = axis_map.begin(); std::multimap<float, int>::iterator it = axis_map.begin();
for (k = axis_map.size() / 2; k--; ++it) { for (k = axis_map.size() / 2; k--; ++it) {
new_tris.push_back(it->second); new_tris.push_back(it->second);
} }
+10 -14
View File
@@ -1,7 +1,5 @@
#pragma once
#ifndef MESHCOLLIDER_H #include <vector>
#define MESHCOLLIDER_H
#include "collision.hpp" #include "collision.hpp"
class MeshCollider { class MeshCollider {
@@ -13,7 +11,7 @@ class MeshCollider {
void* surface; void* surface;
int verts[3], index; int verts[3], index;
}; };
MeshCollider(const vector<Vertex>& verts, const vector<Triangle>& tris); MeshCollider(const std::vector<Vertex>& verts, const std::vector<Triangle>& tris);
~MeshCollider(); ~MeshCollider();
//sphere collision //sphere collision
@@ -22,13 +20,13 @@ class MeshCollider {
bool intersects(const MeshCollider& c, const Transform& t) const; bool intersects(const MeshCollider& c, const Transform& t) const;
private: private:
vector<Vertex> vertices; std::vector<Vertex> vertices;
vector<Triangle> triangles; std::vector<Triangle> triangles;
struct Node { struct Node {
Box box; Box box;
Node * left, *right; Node * left, *right;
vector<int> triangles; std::vector<int> triangles;
Node() : left(0), right(0) {} Node() : left(0), right(0) {}
~Node() ~Node()
{ {
@@ -38,13 +36,11 @@ class MeshCollider {
}; };
Node* tree; Node* tree;
vector<Node*> leaves; std::vector<Node*> leaves;
Box nodeBox(const vector<int>& tris); Box nodeBox(const std::vector<int>& tris);
Node* createLeaf(const vector<int>& tris); Node* createLeaf(const std::vector<int>& tris);
Node* createNode(const vector<int>& tris); Node* createNode(const std::vector<int>& tris);
bool collide(const Box& box, const Line& line, float radius, const Transform& tform, Collision* curr_coll, bool collide(const Box& box, const Line& line, float radius, const Transform& tform, Collision* curr_coll,
Node* node); Node* node);
}; };
#endif
+11 -13
View File
@@ -1,25 +1,23 @@
#include "meshloader.hpp" #include "meshloader.hpp"
#include "meshmodel.hpp" #include "meshmodel.hpp"
#include "std.hpp"
struct Tri { struct Tri {
int verts[3]; int verts[3];
}; };
struct Surf { struct Surf {
vector<Tri> tris; std::vector<Tri> tris;
}; };
struct MLMesh { struct MLMesh {
map<Brush, Surf*> brush_map; std::map<Brush, Surf*> brush_map;
vector<Surface::Vertex> verts; std::vector<Surface::Vertex> verts;
MLMesh() {} MLMesh() {}
~MLMesh() ~MLMesh()
{ {
map<Brush, Surf*>::const_iterator it; std::map<Brush, Surf*>::const_iterator it;
for (it = brush_map.begin(); it != brush_map.end(); ++it) { for (it = brush_map.begin(); it != brush_map.end(); ++it) {
delete it->second; delete it->second;
} }
@@ -27,7 +25,7 @@ struct MLMesh {
}; };
static MLMesh* ml_mesh; static MLMesh* ml_mesh;
static vector<MLMesh*> mesh_stack; static std::vector<MLMesh*> mesh_stack;
void MeshLoader::beginMesh() void MeshLoader::beginMesh()
{ {
@@ -77,12 +75,12 @@ void MeshLoader::addTriangle(int v0, int v1, int v2, const Brush& b)
{ {
//find surface //find surface
Surf* surf; Surf* surf;
map<Brush, Surf*>::const_iterator it = ml_mesh->brush_map.find(b); std::map<Brush, Surf*>::const_iterator it = ml_mesh->brush_map.find(b);
if (it != ml_mesh->brush_map.end()) if (it != ml_mesh->brush_map.end())
surf = it->second; surf = it->second;
else { else {
surf = new Surf; surf = new Surf;
ml_mesh->brush_map.insert(make_pair(b, surf)); ml_mesh->brush_map.insert(std::make_pair(b, surf));
} }
Tri tri; Tri tri;
@@ -115,8 +113,8 @@ void MeshLoader::endMesh(MeshModel* mesh)
v.bone_weights[j] *= t; v.bone_weights[j] *= t;
} }
} }
map<int, int> vert_map; std::map<int, int> vert_map;
map<Brush, Surf*>::iterator it; std::map<Brush, Surf*>::iterator it;
for (it = ml_mesh->brush_map.begin(); it != ml_mesh->brush_map.end(); ++it) { for (it = ml_mesh->brush_map.begin(); it != ml_mesh->brush_map.end(); ++it) {
vert_map.clear(); vert_map.clear();
Brush b = it->first; Brush b = it->first;
@@ -128,13 +126,13 @@ void MeshLoader::endMesh(MeshModel* mesh)
Surface::Triangle tri; Surface::Triangle tri;
for (int j = 0; j < 3; ++j) { for (int j = 0; j < 3; ++j) {
int n = t->tris[k].verts[j], id; int n = t->tris[k].verts[j], id;
map<int, int>::const_iterator it = vert_map.find(n); std::map<int, int>::const_iterator it = vert_map.find(n);
if (it != vert_map.end()) if (it != vert_map.end())
id = it->second; id = it->second;
else { else {
id = surf->numVertices(); id = surf->numVertices();
surf->addVertex(ml_mesh->verts[n]); surf->addVertex(ml_mesh->verts[n]);
vert_map.insert(make_pair(n, id)); vert_map.insert(std::make_pair(n, id));
} }
tri.verts[j] = id; tri.verts[j] = id;
} }
+5 -8
View File
@@ -1,15 +1,14 @@
#pragma once
#ifndef MESHLOADER_H #include "brush.hpp"
#define MESHLOADER_H
#include "model.hpp"
#include "surface.hpp" #include "surface.hpp"
class MeshModel;
class MeshLoader { class MeshLoader {
public: public:
enum { HINT_COLLAPSE = 1, HINT_ANIMONLY = 2 }; enum { HINT_COLLAPSE = 1, HINT_ANIMONLY = 2 };
virtual MeshModel* load(const string& f, const Transform& conv, int hint) = 0; virtual MeshModel* load(const std::string& f, const Transform& conv, int hint) = 0;
//clear //clear
static void beginMesh(); static void beginMesh();
@@ -35,5 +34,3 @@ class MeshLoader {
//finally, update the mesh... //finally, update the mesh...
static void endMesh(MeshModel* mesh); static void endMesh(MeshModel* mesh);
}; };
#endif
+8 -7
View File
@@ -1,7 +1,8 @@
#include "meshmodel.hpp" #include "meshmodel.hpp"
#include "meshcollider.hpp" #include "meshcollider.hpp"
#include "std.hpp" #include "surface.hpp"
#include <vector>
#include "animator.hpp"
extern gxGraphics* gx_graphics; extern gxGraphics* gx_graphics;
@@ -12,7 +13,7 @@ struct MeshModel::Rep : public Surface::Monitor {
mutable int box_valid, coll_valid, norms_valid; mutable int box_valid, coll_valid, norms_valid;
SurfaceList surfaces; SurfaceList surfaces;
vector<Transform> bone_tforms; std::vector<Transform> bone_tforms;
Rep() : ref_cnt(1), collider(0), box_valid(-1), coll_valid(-1), norms_valid(-1) Rep() : ref_cnt(1), collider(0), box_valid(-1), coll_valid(-1), norms_valid(-1)
{ {
@@ -147,8 +148,8 @@ struct MeshModel::Rep : public Surface::Monitor {
{ {
if (coll_valid != geom_changes) { if (coll_valid != geom_changes) {
delete collider; delete collider;
vector<MeshCollider::Vertex> verts; std::vector<MeshCollider::Vertex> verts;
vector<MeshCollider::Triangle> tris; std::vector<MeshCollider::Triangle> tris;
for (int k = 0; k < surfaces.size(); ++k) { for (int k = 0; k < surfaces.size(); ++k) {
Surface* s = surfaces[k]; Surface* s = surfaces[k];
int j; int j;
@@ -215,7 +216,7 @@ void MeshModel::setRenderBrush(const Brush& b)
void MeshModel::createBones() void MeshModel::createBones()
{ {
setRenderSpace(RENDER_SPACE_WORLD); setRenderSpace(RENDER_SPACE_WORLD);
const vector<Object*>& bones = getAnimator()->getObjects(); const std::vector<Object*>& bones = getAnimator()->getObjects();
surf_bones.resize(bones.size()); surf_bones.resize(bones.size());
@@ -257,7 +258,7 @@ bool MeshModel::render(const RenderContext& rc)
} }
//OK, its boned! //OK, its boned!
const vector<Object*>& bones = getAnimator()->getObjects(); const std::vector<Object*>& bones = getAnimator()->getObjects();
int k; int k;
for (k = 0; k < bones.size(); ++k) { for (k = 0; k < bones.size(); ++k) {
+6 -9
View File
@@ -1,15 +1,14 @@
#pragma once
#ifndef MESHMODEL_H #include <vector>
#define MESHMODEL_H
#include "model.hpp" #include "model.hpp"
#include "surface.hpp" #include "surface.hpp"
class MeshCollider; class MeshCollider;
class Collision;
class MeshModel : public Model { class MeshModel : public Model {
public: public:
typedef vector<Surface*> SurfaceList; typedef std::vector<Surface*> SurfaceList;
MeshModel(); MeshModel();
MeshModel(const MeshModel& t); MeshModel(const MeshModel& t);
@@ -59,11 +58,9 @@ class MeshModel : public Model {
Rep* rep; Rep* rep;
int brush_changes; int brush_changes;
Brush render_brush; Brush render_brush;
vector<Brush> brushes; std::vector<Brush> brushes;
vector<Surface::Bone> surf_bones; std::vector<Surface::Bone> surf_bones;
MeshModel& operator=(const MeshModel&); MeshModel& operator=(const MeshModel&);
}; };
#endif
+1 -2
View File
@@ -1,6 +1,5 @@
#include "meshutil.hpp" #include "meshutil.hpp"
#include "std.hpp" #include "surface.hpp"
MeshModel* MeshUtil::createCube(const Brush& b) MeshModel* MeshUtil::createCube(const Brush& b)
{ {
+1 -6
View File
@@ -1,7 +1,4 @@
#pragma once
#ifndef MESHUTIL_H
#define MESHUTIL_H
#include "meshmodel.hpp" #include "meshmodel.hpp"
struct MeshUtil { struct MeshUtil {
@@ -25,5 +22,3 @@ struct MeshUtil {
static Mesh createCylinder( const Brush &b,int segs ); static Mesh createCylinder( const Brush &b,int segs );
*/ */
}; };
#endif
+1 -3
View File
@@ -1,9 +1,7 @@
#include "mirror.hpp" #include "mirror.hpp"
#include "std.hpp"
Mirror::Mirror() {} Mirror::Mirror() {}
Mirror::Mirror(const Mirror& t) : Object(t) {} Mirror::Mirror(const Mirror& t) : Object(t) {}
Mirror::~Mirror() {} Mirror::~Mirror() {}
+1 -6
View File
@@ -1,7 +1,4 @@
#pragma once
#ifndef MIRROR_H
#define MIRROR_H
#include "object.hpp" #include "object.hpp"
class Mirror : public Object { class Mirror : public Object {
@@ -20,5 +17,3 @@ class Mirror : public Object {
return this; return this;
} }
}; };
#endif
+1 -3
View File
@@ -1,6 +1,4 @@
#include "model.hpp" #include "model.hpp"
#include "std.hpp"
extern gxScene* gx_scene; extern gxScene* gx_scene;
@@ -132,7 +130,7 @@ void Model::enqueue(gxMesh* mesh, int fv, int vc, int ft, int tc, const Brush& b
void Model::renderQueue(int type) void Model::renderQueue(int type)
{ {
vector<MeshQueue*>* que = &queues[type]; std::vector<MeshQueue*>* que = &queues[type];
for (; que->size(); que->pop_back()) { for (; que->size(); que->pop_back()) {
MeshQueue* q = que->back(); MeshQueue* q = que->back();
q->render(); q->render();
+3 -7
View File
@@ -1,10 +1,8 @@
#pragma once
#ifndef MODEL_H
#define MODEL_H
#include "brush.hpp" #include "brush.hpp"
#include "object.hpp" #include "object.hpp"
#include "rendercontext.hpp" #include "rendercontext.hpp"
#include "gxmesh.hpp"
class Sprite; class Sprite;
class Terrain; class Terrain;
@@ -147,9 +145,7 @@ class Model : public Object {
bool auto_fade; bool auto_fade;
float auto_fade_nr, auto_fade_fr; float auto_fade_nr, auto_fade_fr;
vector<MeshQueue*> queues[2]; std::vector<MeshQueue*> queues[2];
void enqueue(MeshQueue* q); void enqueue(MeshQueue* q);
}; };
#endif
+5 -2
View File
@@ -1,6 +1,9 @@
#include "object.hpp" #include "object.hpp"
#include "std.hpp" #include "animator.hpp"
#include <gxruntime.hpp>
#include <gxsound.hpp>
#include <gxchannel.hpp>
extern gxRuntime* gx_runtime; extern gxRuntime* gx_runtime;
+5 -9
View File
@@ -1,14 +1,12 @@
#pragma once
#ifndef OBJECT_H
#define OBJECT_H
#include <vector> #include <vector>
#include "animation.hpp"
#include "animator.hpp"
#include "collision.hpp" #include "collision.hpp"
#include "entity.hpp" #include "entity.hpp"
class gxSound; class gxSound;
class gxChannel;
class Animator;
struct ObjCollision { struct ObjCollision {
Object* with; Object* with;
@@ -121,7 +119,7 @@ class Object : public Entity {
bool obscurer; bool obscurer;
float elapsed; float elapsed;
Vector velocity; Vector velocity;
vector<gxChannel*> channels; std::vector<gxChannel*> channels;
Vector capt_pos, capt_scl; Vector capt_pos, capt_scl;
Quat capt_rot; Quat capt_rot;
mutable Object* last_copy; mutable Object* last_copy;
@@ -136,5 +134,3 @@ class Object : public Entity {
void updateSounds(); void updateSounds();
}; };
#endif
-2
View File
@@ -1,6 +1,4 @@
#include "pivot.hpp" #include "pivot.hpp"
#include "std.hpp"
Pivot::Pivot() {} Pivot::Pivot() {}
+1 -6
View File
@@ -1,7 +1,4 @@
#pragma once
#ifndef PIVOT_H
#define PIVOT_H
#include "object.hpp" #include "object.hpp"
class Pivot : public Object { class Pivot : public Object {
@@ -15,5 +12,3 @@ class Pivot : public Object {
return new Pivot(*this); return new Pivot(*this);
} }
}; };
#endif
+2 -2
View File
@@ -1,8 +1,8 @@
#include "planemodel.hpp" #include "planemodel.hpp"
#include "camera.hpp" #include "camera.hpp"
#include "frustum.hpp" #include "frustum.hpp"
#include "std.hpp"
#include <gxgraphics.hpp>
static Vector vts[17][17]; static Vector vts[17][17];
+1 -6
View File
@@ -1,7 +1,4 @@
#pragma once
#ifndef PLANEMODEL_H
#define PLANEMODEL_H
#include "brush.hpp" #include "brush.hpp"
#include "model.hpp" #include "model.hpp"
@@ -33,5 +30,3 @@ class PlaneModel : public Model {
return this; return this;
} }
}; };
#endif
+3 -5
View File
@@ -1,15 +1,13 @@
#include "q3bspmodel.hpp" #include "q3bspmodel.hpp"
#include "q3bsprep.hpp" #include "q3bsprep.hpp"
#include "std.hpp"
struct Q3BSPModel::Rep : public Q3BSPRep { struct Q3BSPModel::Rep : public Q3BSPRep {
int ref_cnt; int ref_cnt;
Rep(const string& f, float gam) : Q3BSPRep(f, gam), ref_cnt(1) {} Rep(const std::string& f, float gam) : Q3BSPRep(f, gam), ref_cnt(1) {}
}; };
Q3BSPModel::Q3BSPModel(const string& f, float gam) : rep(new Rep(f, gam)) {} Q3BSPModel::Q3BSPModel(const std::string& f, float gam) : rep(new Rep(f, gam)) {}
Q3BSPModel::Q3BSPModel(const Q3BSPModel& t) : Model(t), rep(t.rep) Q3BSPModel::Q3BSPModel(const Q3BSPModel& t) : Model(t), rep(t.rep)
{ {
@@ -46,4 +44,4 @@ void Q3BSPModel::setLighting(bool l)
bool Q3BSPModel::isValid() const bool Q3BSPModel::isValid() const
{ {
return rep->isValid(); return rep->isValid();
} }
+2 -7
View File
@@ -1,12 +1,9 @@
#pragma once
#ifndef Q3BSPMODEL_H
#define Q3BSPMODEL_H
#include "model.hpp" #include "model.hpp"
class Q3BSPModel : public Model { class Q3BSPModel : public Model {
public: public:
Q3BSPModel(const string& f, float gamma_adj); Q3BSPModel(const std::string& f, float gamma_adj);
Q3BSPModel(const Q3BSPModel& m); Q3BSPModel(const Q3BSPModel& m);
~Q3BSPModel(); ~Q3BSPModel();
@@ -36,5 +33,3 @@ class Q3BSPModel : public Model {
struct Rep; struct Rep;
Rep* rep; Rep* rep;
}; };
#endif
+25 -23
View File
@@ -1,6 +1,8 @@
#include "q3bsprep.hpp" #include "q3bsprep.hpp"
#include "std.hpp"
#include <gxgraphics.hpp>
#include <gxcanvas.hpp>
#include <stdutil.hpp>
/* Quake3 File format types */ /* Quake3 File format types */
@@ -89,7 +91,7 @@ struct q3_header {
struct Surf { struct Surf {
Q3BSPSurf* surf; Q3BSPSurf* surf;
int texture, lm_index; int texture, lm_index;
vector<int> verts, tris; std::vector<int> verts, tris;
}; };
struct FaceCmp { struct FaceCmp {
@@ -105,7 +107,7 @@ struct FaceCmp {
} }
}; };
typedef map<q3_face*, Surf*, FaceCmp> FaceMap; typedef std::map<q3_face*, Surf*, FaceCmp> FaceMap;
/* render reps */ /* render reps */
@@ -114,7 +116,7 @@ struct Q3BSPFace;
struct Q3BSPSurf { struct Q3BSPSurf {
Brush brush; Brush brush;
gxMesh* mesh; gxMesh* mesh;
vector<Q3BSPFace*> r_faces; std::vector<Q3BSPFace*> r_faces;
int texture, lm_index; int texture, lm_index;
}; };
@@ -127,13 +129,13 @@ struct Q3BSPFace {
}; };
struct Q3BSPBrush { struct Q3BSPBrush {
vector<Plane> planes; std::vector<Plane> planes;
}; };
struct Q3BSPLeaf { struct Q3BSPLeaf {
int cluster; int cluster;
Box box; Box box;
vector<Q3BSPFace*> faces; std::vector<Q3BSPFace*> faces;
}; };
struct Q3BSPNode { struct Q3BSPNode {
@@ -153,10 +155,10 @@ struct Q3BSPNode {
static q3_header header; static q3_header header;
static FaceMap face_map; static FaceMap face_map;
static vector<Surf*> t_surfs; static std::vector<Surf*> t_surfs;
static vector<q3_vertex> p_verts; //patch vertices static std::vector<q3_vertex> p_verts; //patch vertices
static vector<Vector> p_coll_verts; static std::vector<Vector> p_coll_verts;
static vector<MeshCollider::Triangle> coll_tris; static std::vector<MeshCollider::Triangle> coll_tris;
static float gamma_adj; static float gamma_adj;
@@ -164,7 +166,7 @@ static Vector r_eye;
static int r_cluster; static int r_cluster;
static Frustum r_frustum; static Frustum r_frustum;
static Vector r_frustedges[12]; static Vector r_frustedges[12];
static map<int, Q3BSPFace*> q3face_map; static std::map<int, Q3BSPFace*> q3face_map;
extern gxScene* gx_scene; extern gxScene* gx_scene;
extern gxRuntime* gx_runtime; extern gxRuntime* gx_runtime;
@@ -182,7 +184,7 @@ static void debuglog(const string& t)
gx_runtime->debugLog(t.c_str()); gx_runtime->debugLog(t.c_str());
} }
#else #else
static void debuglog(const string& t) {} static void debuglog(const std::string& t) {}
#endif #endif
static Surf* findSurf(q3_face* f) static Surf* findSurf(q3_face* f)
@@ -193,7 +195,7 @@ static Surf* findSurf(q3_face* f)
Surf* s = new Surf; Surf* s = new Surf;
s->texture = f->texture; s->texture = f->texture;
s->lm_index = f->lm_index; s->lm_index = f->lm_index;
face_map.insert(make_pair(f, s)); face_map.insert(std::make_pair(f, s));
t_surfs.push_back(s); t_surfs.push_back(s);
return s; return s;
} }
@@ -203,7 +205,7 @@ void Q3BSPRep::createTextures()
int n_texs = header.dir[1].length / sizeof(q3_tex); int n_texs = header.dir[1].length / sizeof(q3_tex);
q3_tex* q3tex = (q3_tex*)header.dir[1].lump; q3_tex* q3tex = (q3_tex*)header.dir[1].lump;
for (int k = 0; k < n_texs; ++k) { for (int k = 0; k < n_texs; ++k) {
string t = string(q3tex->name); std::string t = std::string(q3tex->name);
char fl[32], co[32]; char fl[32], co[32];
_itoa(q3tex->flags, fl, 16); _itoa(q3tex->flags, fl, 16);
_itoa(q3tex->contents, co, 16); _itoa(q3tex->contents, co, 16);
@@ -264,7 +266,7 @@ void Q3BSPRep::createVis()
void Q3BSPRep::createCollider() void Q3BSPRep::createCollider()
{ {
vector<MeshCollider::Vertex> coll_verts; std::vector<MeshCollider::Vertex> coll_verts;
int n_verts = header.dir[10].length / sizeof(q3_vertex); int n_verts = header.dir[10].length / sizeof(q3_vertex);
q3_vertex* t = (q3_vertex*)header.dir[10].lump; q3_vertex* t = (q3_vertex*)header.dir[10].lump;
MeshCollider::Vertex cv; MeshCollider::Vertex cv;
@@ -350,7 +352,7 @@ static void average(const q3_vertex& a, const q3_vertex& b, q3_vertex* c)
} }
} }
static void subdivide(vector<q3_vertex>& verts, int level, int index, int step) static void subdivide(std::vector<q3_vertex>& verts, int level, int index, int step)
{ {
if (!level) { if (!level) {
q3_vertex t1, t2; q3_vertex t1, t2;
@@ -369,7 +371,7 @@ static void subdivide(vector<q3_vertex>& verts, int level, int index, int step)
static void patchFace(Q3BSPFace* face, q3_face* q3face, bool draw, bool solid, int level) static void patchFace(Q3BSPFace* face, q3_face* q3face, bool draw, bool solid, int level)
{ {
int k, x, y; int k, x, y;
vector<q3_vertex> verts; std::vector<q3_vertex> verts;
if (draw) { if (draw) {
int step = 1 << level; int step = 1 << level;
@@ -422,7 +424,7 @@ static void patchFace(Q3BSPFace* face, q3_face* q3face, bool draw, bool solid, i
} }
if (solid) { if (solid) {
vector<q3_vertex> verts; std::vector<q3_vertex> verts;
int step = 1; int step = 1;
int size_x = q3face->patch_size[0]; int size_x = q3face->patch_size[0];
int size_y = q3face->patch_size[1]; int size_y = q3face->patch_size[1];
@@ -472,7 +474,7 @@ static void patchFace(Q3BSPFace* face, q3_face* q3face, bool draw, bool solid, i
static void meshFace(Q3BSPFace* face, q3_face* q3face, bool draw, bool solid) static void meshFace(Q3BSPFace* face, q3_face* q3face, bool draw, bool solid)
{ {
static map<int, int> vert_map; static std::map<int, int> vert_map;
vert_map.clear(); vert_map.clear();
int* meshverts = (int*)header.dir[11].lump + q3face->meshvert; int* meshverts = (int*)header.dir[11].lump + q3face->meshvert;
MeshCollider::Triangle ct; MeshCollider::Triangle ct;
@@ -529,7 +531,7 @@ Q3BSPLeaf* Q3BSPRep::createLeaf(int n)
for (int k = 0; k < q3leaf->n_leaffaces; ++k) { for (int k = 0; k < q3leaf->n_leaffaces; ++k) {
int face_n = leaffaces[k]; int face_n = leaffaces[k];
map<int, Q3BSPFace*>::const_iterator it = q3face_map.find(face_n); std::map<int, Q3BSPFace*>::const_iterator it = q3face_map.find(face_n);
if (it != q3face_map.end()) { if (it != q3face_map.end()) {
if (it->second) if (it->second)
leaf->faces.push_back(it->second); leaf->faces.push_back(it->second);
@@ -567,7 +569,7 @@ Q3BSPLeaf* Q3BSPRep::createLeaf(int n)
face->n_verts = face->n_tris = 0; face->n_verts = face->n_tris = 0;
leaf->faces.push_back(face); leaf->faces.push_back(face);
faces.push_back(face); faces.push_back(face);
q3face_map.insert(make_pair(face_n, face)); q3face_map.insert(std::make_pair(face_n, face));
} }
if (q3face->type == 2) { if (q3face->type == 2) {
@@ -608,7 +610,7 @@ Q3BSPNode* Q3BSPRep::createNode(int n)
return node; return node;
} }
Q3BSPRep::Q3BSPRep(const string& f, float gam) : root_node(0), vis_sz(0), vis_data(0), use_lmap(true) Q3BSPRep::Q3BSPRep(const std::string& f, float gam) : root_node(0), vis_sz(0), vis_data(0), use_lmap(true)
{ {
gamma_adj = 1 - gam; gamma_adj = 1 - gam;
+7 -10
View File
@@ -1,7 +1,6 @@
#pragma once
#ifndef Q3BSPREP_H #include <string>
#define Q3BSPREP_H #include <vector>
#include "meshcollider.hpp" #include "meshcollider.hpp"
#include "model.hpp" #include "model.hpp"
@@ -13,7 +12,7 @@ struct Q3BSPNode;
class Q3BSPRep { class Q3BSPRep {
public: public:
//constructor //constructor
Q3BSPRep(const string& f, float gamma_adj); Q3BSPRep(const std::string& f, float gamma_adj);
~Q3BSPRep(); ~Q3BSPRep();
void render(Model* model, const RenderContext& rc); void render(Model* model, const RenderContext& rc);
@@ -32,9 +31,9 @@ class Q3BSPRep {
Vector ambient; Vector ambient;
vector<Q3BSPFace*> faces; std::vector<Q3BSPFace*> faces;
vector<Q3BSPSurf*> surfs, r_surfs; std::vector<Q3BSPSurf*> surfs, r_surfs;
vector<Texture> textures, light_maps; std::vector<Texture> textures, light_maps;
int vis_sz; int vis_sz;
char* vis_data; char* vis_data;
@@ -55,5 +54,3 @@ class Q3BSPRep {
void render(Q3BSPLeaf* l, int clip); void render(Q3BSPLeaf* l, int clip);
void render(Q3BSPNode* n, int clip); void render(Q3BSPNode* n, int clip);
}; };
#endif
+1 -6
View File
@@ -1,7 +1,4 @@
#pragma once
#ifndef RENDERCONTEXT_H
#define RENDERCONTEXT_H
#include "frustum.hpp" #include "frustum.hpp"
class RenderContext { class RenderContext {
@@ -33,5 +30,3 @@ class RenderContext {
Frustum world_frustum, camera_frustum; Frustum world_frustum, camera_frustum;
bool ref; bool ref;
}; };
#endif
+4 -3
View File
@@ -1,6 +1,7 @@
#include "sprite.hpp" #include "sprite.hpp"
#include "std.hpp"
#include <gxgraphics.hpp>
#include <gxruntime.hpp>
extern float stats3d[]; extern float stats3d[];
@@ -16,7 +17,7 @@ extern gxGraphics* gx_graphics;
static gxMesh* mesh; static gxMesh* mesh;
static int mesh_size; static int mesh_size;
static vector<int> mesh_indices; static std::vector<int> mesh_indices;
static int allocIndex() static int allocIndex()
{ {
+1 -6
View File
@@ -1,7 +1,4 @@
#pragma once
#ifndef SPRITE_H
#define SPRITE_H
#include "brush.hpp" #include "brush.hpp"
#include "gxmesh.hpp" #include "gxmesh.hpp"
#include "model.hpp" #include "model.hpp"
@@ -46,5 +43,3 @@ class Sprite : public Model {
int view_mode, mesh_index; int view_mode, mesh_index;
bool captured; bool captured;
}; };
#endif
-2
View File
@@ -1,2 +0,0 @@
#include "std.hpp"
-20
View File
@@ -1,20 +0,0 @@
#ifndef STD_H
#define STD_H
#pragma warning(disable : 4786)
#include "config.hpp"
#include "gxruntime.hpp"
#include "stdutil.hpp"
#include <fstream>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
#endif
+7 -7
View File
@@ -1,6 +1,6 @@
#include "surface.hpp" #include "surface.hpp"
#include "std.hpp"
#include <gxgraphics.hpp>
extern gxGraphics* gx_graphics; extern gxGraphics* gx_graphics;
@@ -22,7 +22,7 @@ void Surface::setBrush(const Brush& b)
++mon->brush_changes; ++mon->brush_changes;
} }
void Surface::setName(const string& n) void Surface::setName(const std::string& n)
{ {
name = n; name = n;
} }
@@ -40,7 +40,7 @@ void Surface::clear(bool verts, bool tris)
++mon->geom_changes; ++mon->geom_changes;
} }
void Surface::addVertices(const vector<Vertex>& verts) void Surface::addVertices(const std::vector<Vertex>& verts)
{ {
vertices.insert(vertices.end(), verts.begin(), verts.end()); vertices.insert(vertices.end(), verts.begin(), verts.end());
++mon->geom_changes; ++mon->geom_changes;
@@ -79,7 +79,7 @@ Vector Surface::getColor(int n) const
return Vector(r / 255.0f, g / 255.0f, b / 255.0f); return Vector(r / 255.0f, g / 255.0f, b / 255.0f);
} }
void Surface::addTriangles(const vector<Triangle>& tris) void Surface::addTriangles(const std::vector<Triangle>& tris)
{ {
triangles.insert(triangles.end(), tris.begin(), tris.end()); triangles.insert(triangles.end(), tris.begin(), tris.end());
} }
@@ -87,7 +87,7 @@ void Surface::addTriangles(const vector<Triangle>& tris)
void Surface::updateNormals() void Surface::updateNormals()
{ {
int k; int k;
map<Vector, Vector> norm_map; std::map<Vector, Vector> norm_map;
for (k = 0; k < triangles.size(); ++k) { for (k = 0; k < triangles.size(); ++k) {
const Triangle& t = triangles[k]; const Triangle& t = triangles[k];
const Vector& v0 = vertices[t.verts[0]].coords; const Vector& v0 = vertices[t.verts[0]].coords;
@@ -141,7 +141,7 @@ gxMesh* Surface::getMesh()
return mesh; return mesh;
} }
gxMesh* Surface::getMesh(const vector<Bone>& bones) gxMesh* Surface::getMesh(const std::vector<Bone>& bones)
{ {
valid_vs = valid_ts = 0; valid_vs = valid_ts = 0;
+12 -14
View File
@@ -1,8 +1,8 @@
#pragma once
#ifndef SURFACE_H
#define SURFACE_H
#include "model.hpp" #include "model.hpp"
#include "geom.hpp"
#include "gxmesh.hpp"
#include <vector>
#define MAX_SURFACE_BONES 4 #define MAX_SURFACE_BONES 4
@@ -45,7 +45,7 @@ class Surface {
Surface(Monitor* mon); Surface(Monitor* mon);
~Surface(); ~Surface();
void setName(const string& t); void setName(const std::string& t);
void setBrush(const Brush& b); void setBrush(const Brush& b);
void clear(bool verts, bool tris); void clear(bool verts, bool tris);
@@ -103,15 +103,15 @@ class Surface {
Vector getColor(int index) const; Vector getColor(int index) const;
void setColor(int index, const Vector& v); void setColor(int index, const Vector& v);
void addVertices(const vector<Vertex>& verts); void addVertices(const std::vector<Vertex>& verts);
void addTriangles(const vector<Triangle>& tris); void addTriangles(const std::vector<Triangle>& tris);
void updateNormals(); void updateNormals();
gxMesh* getMesh(); gxMesh* getMesh();
gxMesh* getMesh(const vector<Bone>& bones); gxMesh* getMesh(const std::vector<Bone>& bones);
string getName() const std::string getName() const
{ {
return name; return name;
} }
@@ -138,13 +138,11 @@ class Surface {
private: private:
Brush brush; Brush brush;
string name; std::string name;
gxMesh* mesh; gxMesh* mesh;
vector<Vertex> vertices; std::vector<Vertex> vertices;
vector<Triangle> triangles; std::vector<Triangle> triangles;
int mesh_vs, mesh_ts; int mesh_vs, mesh_ts;
int valid_vs, valid_ts; int valid_vs, valid_ts;
Monitor* mon; Monitor* mon;
}; };
#endif
-2
View File
@@ -1,6 +1,4 @@
#include "terrain.hpp" #include "terrain.hpp"
#include "std.hpp"
#include "terrainrep.hpp" #include "terrainrep.hpp"
Terrain::Terrain(int size_shift) : rep(new TerrainRep(size_shift)) {} Terrain::Terrain(int size_shift) : rep(new TerrainRep(size_shift)) {}
+1 -6
View File
@@ -1,7 +1,4 @@
#pragma once
#ifndef TERRAIN_H
#define TERRAIN_H
#include "model.hpp" #include "model.hpp"
struct TerrainRep; struct TerrainRep;
@@ -32,5 +29,3 @@ class Terrain : public Model {
private: private:
TerrainRep* rep; TerrainRep* rep;
}; };
#endif
+26 -25
View File
@@ -1,19 +1,24 @@
#include "terrainrep.hpp" #include "terrainrep.hpp"
#include <queue> #include <queue>
#include "std.hpp"
#include <gxgraphics.hpp>
#include <gxruntime.hpp>
extern gxRuntime* gx_runtime; extern gxRuntime* gx_runtime;
extern gxGraphics* gx_graphics; extern gxGraphics* gx_graphics;
extern float stats3d[10]; extern float stats3d[10];
static Vector eye_vec; static Vector eye_vec;
static Plane eye_plane; static Plane eye_plane;
static const Vector up_normal(0, 1, 0); static const Vector up_normal(0, 1, 0);
static TerrainRep::Tri* tri_pool; static TerrainRep::Tri* tri_pool;
static const TerrainRep* curr; static const TerrainRep* curr;
static Frustum frustum; static Frustum frustum;
static int out_cnt, proc_cnt, clip_cnt; static int out_cnt, proc_cnt, clip_cnt;
static std::vector<TerrainRep::Tri*> tris;
static int vert_cnt, max_verts;
static TerrainRep::Vert *verts, *next_vert;
static float proj_epsilon = FLT_EPSILON; //.01f; static float proj_epsilon = FLT_EPSILON; //.01f;
@@ -48,9 +53,6 @@ struct TerrainRep::Vert {
Vert(int x, int z, float sy) : x(x), z(z), v((float)x, curr->getHeight(x, z), (float)z), src_y(sy) {} Vert(int x, int z, float sy) : x(x), z(z), v((float)x, curr->getHeight(x, z), (float)z), src_y(sy) {}
}; };
static int vert_cnt, max_verts;
static TerrainRep::Vert *verts, *next_vert;
struct TerrainRep::Tri { struct TerrainRep::Tri {
int id; int id;
short clip, v0, v1, v2; short clip, v0, v1, v2;
@@ -66,20 +68,20 @@ struct TerrainRep::Tri {
{ {
static const int GROW = 64; static const int GROW = 64;
if (!tri_pool) { if (!tri_pool) {
tri_pool = new Tri[GROW]; tri_pool = new TerrainRep::Tri[GROW];
for (int k = 0; k < GROW - 1; ++k) for (int k = 0; k < GROW - 1; ++k)
tri_pool[k].e0 = &tri_pool[k + 1]; tri_pool[k].e0 = &tri_pool[k + 1];
tri_pool[GROW - 1].e0 = 0; tri_pool[GROW - 1].e0 = 0;
} }
Tri* t = tri_pool; TerrainRep::Tri* t = tri_pool;
tri_pool = t->e0; tri_pool = t->e0;
return t; return t;
} }
void operator delete(void* q) void operator delete(void* q)
{ {
Tri* t = (Tri*)q; TerrainRep::Tri* t = (TerrainRep::Tri*)q;
t->e0 = tri_pool; t->e0 = tri_pool;
tri_pool = t; tri_pool = t;
} }
void unlink() void unlink()
{ {
@@ -117,19 +119,18 @@ struct TriComp {
} }
}; };
struct TriQue : public priority_queue<TerrainRep::Tri*, vector<TerrainRep::Tri*>, TriComp> { struct TriQue : public std::priority_queue<TerrainRep::Tri*, std::vector<TerrainRep::Tri*>, TriComp> {
vector<TerrainRep::Tri*>& getVector() std::vector<TerrainRep::Tri*>& getVector()
{ {
return c; return c;
} }
const vector<TerrainRep::Tri*>& getVector() const const std::vector<TerrainRep::Tri*>& getVector() const
{ {
return c; return c;
} }
}; };
static TriQue tri_que; static TriQue tri_que;
static vector<TerrainRep::Tri*> tris;
static bool clip(const Line& l, const Box& box) static bool clip(const Line& l, const Box& box)
{ {
@@ -497,8 +498,8 @@ void TerrainRep::render(Model* model, const RenderContext& rc)
delete t; delete t;
} }
int k; int k;
const vector<Tri*>& q_tris = tri_que.getVector(); const std::vector<Tri*>& q_tris = tri_que.getVector();
if (!mesh) if (!mesh)
out_cnt = 0; out_cnt = 0;
+1 -8
View File
@@ -1,9 +1,4 @@
#pragma once
#ifndef TERRAINREP_H
#define TERRAINREP_H
#include <queue>
#include "model.hpp" #include "model.hpp"
struct TerrainRep { struct TerrainRep {
@@ -53,5 +48,3 @@ struct TerrainRep {
bool collide(const Line& line, float radius, Collision* curr_coll, const Transform& tform, int id, const Vert& v0, bool collide(const Line& line, float radius, Collision* curr_coll, const Transform& tform, int id, const Vert& v0,
const Vert& v1, const Vert& v2, const Box& box) const; const Vert& v1, const Vert& v2, const Box& box) const;
}; };
#endif
+18 -18
View File
@@ -1,28 +1,28 @@
#include "texture.hpp" #include "texture.hpp"
#include "cachedtexture.hpp" #include "cachedtexture.hpp"
#include "geom.hpp" #include "geom.hpp"
#include "std.hpp"
#include "../gxruntime/gxgraphics.hpp" #include <gxgraphics.hpp>
#include <gxcanvas.hpp>
#include <stdutil.hpp>
extern gxScene* gx_scene; extern gxScene* gx_scene;
extern gxGraphics* gx_graphics; extern gxGraphics* gx_graphics;
struct Filter { struct Filter {
string t; std::string t;
int flags; int flags;
Filter(const string& t, int flags) : t(t), flags(flags) {} Filter(const std::string& t, int flags) : t(t), flags(flags) {}
}; };
static vector<Filter> filters; static std::vector<Filter> filters;
static int filterFile(const string& t, int flags) static int filterFile(const std::string& t, int flags)
{ {
//check filters... //check filters...
string l = tolower(t); std::string l = tolower(t);
for (size_t k = 0; k < filters.size(); ++k) { for (size_t k = 0; k < filters.size(); ++k) {
if (l.find(filters[k].t) != string::npos) { if (l.find(filters[k].t) != std::string::npos) {
flags |= filters[k].flags; flags |= filters[k].flags;
} }
} }
@@ -30,9 +30,9 @@ static int filterFile(const string& t, int flags)
} }
struct Texture::Rep { struct Texture::Rep {
int ref_cnt; int ref_cnt;
CachedTextureFactory cached_tex; CachedTexture cached_tex;
vector<gxCanvas*> tex_frames; std::vector<gxCanvas*> tex_frames;
int tex_blend, tex_flags; int tex_blend, tex_flags;
bool transparent; bool transparent;
@@ -50,7 +50,7 @@ struct Texture::Rep {
memset(&matrix, 0, sizeof(matrix)); memset(&matrix, 0, sizeof(matrix));
} }
Rep(const string& f, int flags, int w, int h, int first, int cnt) Rep(const std::string& f, int flags, int w, int h, int first, int cnt)
: ref_cnt(1), cached_tex(f, flags, w, h, first, cnt), tex_blend(gxScene::BLEND_MULTIPLY), tex_flags(0), sx(1), : ref_cnt(1), cached_tex(f, flags, w, h, first, cnt), tex_blend(gxScene::BLEND_MULTIPLY), tex_flags(0), sx(1),
sy(1), tx(0), ty(0), rot(0), mat_used(false) sy(1), tx(0), ty(0), rot(0), mat_used(false)
{ {
@@ -68,7 +68,7 @@ struct Texture::Rep {
Texture::Texture() : rep(0) {} Texture::Texture() : rep(0) {}
Texture::Texture(const string& f, int flags) Texture::Texture(const std::string& f, int flags)
{ {
flags = filterFile(f, flags) | gxCanvas::CANVAS_TEXTURE; flags = filterFile(f, flags) | gxCanvas::CANVAS_TEXTURE;
if (flags & gxCanvas::CANVAS_TEX_MASK) if (flags & gxCanvas::CANVAS_TEX_MASK)
@@ -76,7 +76,7 @@ Texture::Texture(const string& f, int flags)
rep = new Rep(f, flags, 0, 0, 0, 1); rep = new Rep(f, flags, 0, 0, 0, 1);
} }
Texture::Texture(const string& f, int flags, int w, int h, int first, int cnt) Texture::Texture(const std::string& f, int flags, int w, int h, int first, int cnt)
{ {
flags = filterFile(f, flags) | gxCanvas::CANVAS_TEXTURE; flags = filterFile(f, flags) | gxCanvas::CANVAS_TEXTURE;
if (flags & gxCanvas::CANVAS_TEX_MASK) if (flags & gxCanvas::CANVAS_TEX_MASK)
@@ -172,7 +172,7 @@ int Texture::getCanvasFlags() const
return rep && rep->tex_frames.size() ? rep->tex_frames[0]->getFlags() : 0; return rep && rep->tex_frames.size() ? rep->tex_frames[0]->getFlags() : 0;
} }
CachedTextureFactory* Texture::getCachedTexture() const CachedTexture* Texture::getCachedTexture() const
{ {
return rep ? &rep->cached_tex : 0; return rep ? &rep->cached_tex : 0;
} }
@@ -216,7 +216,7 @@ void Texture::clearFilters()
filters.clear(); filters.clear();
} }
void Texture::addFilter(const string& t, int flags) void Texture::addFilter(const std::string& t, int flags)
{ {
filters.push_back(Filter(tolower(t), flags)); filters.push_back(Filter(tolower(t), flags));
} }
+5 -9
View File
@@ -1,12 +1,10 @@
#pragma once
#ifndef TEXTURE_H
#define TEXTURE_H
#include <string> #include <string>
#include "cachedtexture.hpp" #include "cachedtexture.hpp"
#include "gxcanvas.hpp" #include <gxscene.hpp>
class gxCanvas;
class Texture { class Texture {
public: public:
@@ -30,7 +28,7 @@ class Texture {
const gxScene::Matrix* getMatrix() const; const gxScene::Matrix* getMatrix() const;
int getBlend() const; int getBlend() const;
int getFlags() const; int getFlags() const;
CachedTextureFactory* getCachedTexture() const; CachedTexture* getCachedTexture() const;
bool isTransparent() const; bool isTransparent() const;
bool operator<(const Texture& t) const; bool operator<(const Texture& t) const;
@@ -42,5 +40,3 @@ class Texture {
struct Rep; struct Rep;
Rep* rep; Rep* rep;
}; };
#endif
+17 -18
View File
@@ -1,7 +1,6 @@
#include "world.hpp" #include "world.hpp"
#include <queue> #include <queue>
#include "std.hpp" #include "gxruntime.hpp"
//0=tris compared for collision //0=tris compared for collision
//1=max proj err of terrain //1=max proj err of terrain
@@ -30,9 +29,9 @@ static void StaticEnumerateVisible()
/******************************* Update *******************************/ /******************************* Update *******************************/
static vector<Object*> _objsByType[1000]; static std::vector<Object*> _objsByType[1000];
static vector<ObjCollision*> free_colls, used_colls; static std::vector<ObjCollision*> free_colls, used_colls;
static ObjCollision* allocObjColl(Object* with, const Vector& coords, const Collision& coll) static ObjCollision* allocObjColl(Object* with, const Vector& coords, const Collision& coll)
{ {
@@ -73,7 +72,7 @@ void World::clearCollisions()
void World::addCollision(int src_type, int dst_type, int method, int response) void World::addCollision(int src_type, int dst_type, int method, int response)
{ {
vector<CollInfo>& info = _collInfo[src_type]; std::vector<CollInfo>& info = _collInfo[src_type];
for (size_t k = 0; k < info.size(); ++k) { for (size_t k = 0; k < info.size(); ++k) {
const CollInfo& t = info[k]; const CollInfo& t = info[k];
if (dst_type == t.dst_type) if (dst_type == t.dst_type)
@@ -183,13 +182,13 @@ void World::collide(Object* src)
float td = coll_line.d.length(); float td = coll_line.d.length();
float td_xz = Vector(coll_line.d.x, 0, coll_line.d.z).length(); float td_xz = Vector(coll_line.d.x, 0, coll_line.d.z).length();
const vector<CollInfo>& collinfos = _collInfo[src->getCollisionType()]; const std::vector<CollInfo>& collinfos = _collInfo[src->getCollisionType()];
int hits = 0; int hits = 0;
for (;;) { for (;;) {
Collision coll; Collision coll;
Object* coll_obj = 0; Object* coll_obj = 0;
vector<CollInfo>::const_iterator coll_it, coll_info; std::vector<CollInfo>::const_iterator coll_it, coll_info;
for (coll_it = collinfos.begin(); coll_it != collinfos.end(); ++coll_it) { for (coll_it = collinfos.begin(); coll_it != collinfos.end(); ++coll_it) {
// const std::list<Object*> &dst_objs = _objsByType[coll_it->dst_type]; // const std::list<Object*> &dst_objs = _objsByType[coll_it->dst_type];
@@ -501,9 +500,9 @@ void World::update(float elapsed)
static Transform cam_tform; //current camera transform static Transform cam_tform; //current camera transform
static vector<gxLight*> _lights; static std::vector<gxLight*> _lights;
static vector<Mirror*> _mirrors; static std::vector<Mirror*> _mirrors;
static vector<Listener*> _listeners; static std::vector<Listener*> _listeners;
struct OrderComp { struct OrderComp {
bool operator()(Object* a, Object* b) bool operator()(Object* a, Object* b)
@@ -519,13 +518,13 @@ struct TransComp {
} }
}; };
static vector<Model*> ord_mods, unord_mods; static std::vector<Model*> ord_mods, unord_mods;
static priority_queue<Model*, vector<Model*>, OrderComp> ord_que; static std::priority_queue<Model*, std::vector<Model*>, OrderComp> ord_que;
static priority_queue<Camera*, vector<Camera*>, OrderComp> cam_que; static std::priority_queue<Camera*, std::vector<Camera*>, OrderComp> cam_que;
static priority_queue<Model*, vector<Model*>, TransComp> transparents; static std::priority_queue<Model*, std::vector<Model*>, TransComp> transparents;
void World::capture() void World::capture()
{ {
@@ -583,7 +582,7 @@ void World::render(float tween)
if (!cam->beginRenderFrame()) if (!cam->beginRenderFrame())
continue; continue;
vector<Mirror*>::const_iterator mir_it; std::vector<Mirror*>::const_iterator mir_it;
for (mir_it = _mirrors.begin(); mir_it != _mirrors.end(); ++mir_it) { for (mir_it = _mirrors.begin(); mir_it != _mirrors.end(); ++mir_it) {
render(cam, *mir_it); render(cam, *mir_it);
} }
@@ -595,7 +594,7 @@ void World::render(float tween)
// gx_runtime->debugLog( "End RenderWorld" ); // gx_runtime->debugLog( "End RenderWorld" );
vector<Listener*>::const_iterator lis_it; std::vector<Listener*>::const_iterator lis_it;
for (lis_it = _listeners.begin(); lis_it != _listeners.end(); ++lis_it) { for (lis_it = _listeners.begin(); lis_it != _listeners.end(); ++lis_it) {
(*lis_it)->renderListener(); (*lis_it)->renderListener();
} }
+2 -8
View File
@@ -1,9 +1,5 @@
#pragma once
#ifndef WORLD_H
#define WORLD_H
#include <list> #include <list>
#include "camera.hpp" #include "camera.hpp"
#include "light.hpp" #include "light.hpp"
#include "listener.hpp" #include "listener.hpp"
@@ -42,7 +38,7 @@ class World {
int dst_type, method, response; int dst_type, method, response;
}; };
vector<CollInfo> _collInfo[WORLD_COLLISION_TYPES]; std::vector<CollInfo> _collInfo[WORLD_COLLISION_TYPES];
std::list<Object*> _objsByType[WORLD_COLLISION_TYPES]; std::list<Object*> _objsByType[WORLD_COLLISION_TYPES];
std::list<Object*> _objsByTypeSwappable[WORLD_COLLISION_TYPES]; std::list<Object*> _objsByTypeSwappable[WORLD_COLLISION_TYPES];
@@ -51,5 +47,3 @@ class World {
void render(Model* m, const RenderContext& rc); void render(Model* m, const RenderContext& rc);
void flushTransparent(); void flushTransparent();
}; };
#endif