summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFWoltermann@gmail.com <FWoltermann@gmail.com@076cb2c4-205e-83fd-5cf3-1be9aa105544>2012-05-26 16:43:59 +0000
committerFWoltermann@gmail.com <FWoltermann@gmail.com@076cb2c4-205e-83fd-5cf3-1be9aa105544>2012-05-26 16:43:59 +0000
commitf04d3710278e0dd5451e99a4969caf9d1a6a5092 (patch)
treeb99046e2b0ab0c7b166f8078cc3c71c68f39029a
parent9a9de7689176de013872e5a6a5367f79202d0844 (diff)
downloadstarshatter-f04d3710278e0dd5451e99a4969caf9d1a6a5092.zip
starshatter-f04d3710278e0dd5451e99a4969caf9d1a6a5092.tar.gz
starshatter-f04d3710278e0dd5451e99a4969caf9d1a6a5092.tar.bz2
And the rest that was missing to make this thing compile.
-rw-r--r--Magic2/ContentBundle.cpp137
-rw-r--r--Magic2/ContentBundle.h48
-rw-r--r--Magic2/Locale_ss.cpp237
-rw-r--r--Magic2/Locale_ss.h53
-rw-r--r--Magic2/Magic.vcxproj7
-rw-r--r--Magic2/Magic.vcxproj.filters21
-rw-r--r--Magic2/TexCubeDX9.cpp120
-rw-r--r--Magic2/TexCubeDX9.h49
-rw-r--r--Magic2/VideoDX9.h195
9 files changed, 867 insertions, 0 deletions
diff --git a/Magic2/ContentBundle.cpp b/Magic2/ContentBundle.cpp
new file mode 100644
index 0000000..b489cf8
--- /dev/null
+++ b/Magic2/ContentBundle.cpp
@@ -0,0 +1,137 @@
+/* Project nGenEx
+ Destroyer Studios LLC
+ Copyright © 1997-2006. All Rights Reserved.
+
+ SUBSYSTEM: nGenEx.lib
+ FILE: ContentBundle.cpp
+ AUTHOR: John DiCamillo
+
+
+ OVERVIEW
+ ========
+ Chained collection of localized strings
+*/
+
+#include "MemDebug.h"
+#include "ContentBundle.h"
+#include "DataLoader.h"
+
+void Print(const char* fmt, ...);
+
+// +--------------------------------------------------------------------+
+
+ContentBundle::ContentBundle(const char* bundle, Locale* locale)
+{
+ Text file = FindFile(bundle, locale);
+ if (file.length() > 0) {
+ LoadBundle(file);
+ }
+}
+
+// +--------------------------------------------------------------------+
+
+ContentBundle::~ContentBundle()
+{
+}
+
+// +--------------------------------------------------------------------+
+
+Text
+ContentBundle::GetText(const char* key) const
+{
+ return values.find(key, Text(key));
+}
+
+// +--------------------------------------------------------------------+
+
+Text
+ContentBundle::FindFile(const char* bundle, Locale* locale)
+{
+ Text result;
+ Text basename = Text(bundle);
+ DataLoader* loader = DataLoader::GetLoader();
+
+ if (loader && bundle) {
+ if (locale) {
+ result = basename + locale->GetFullCode() + ".txt";
+
+ if (loader->FindFile(result))
+ return result;
+
+ result = basename + "_" + locale->GetLanguage() + ".txt";
+
+ if (loader->FindFile(result))
+ return result;
+ }
+
+ result = basename + ".txt";
+
+ if (loader->FindFile(result))
+ return result;
+ }
+
+ return Text();
+}
+
+// +--------------------------------------------------------------------+
+
+void
+ContentBundle::LoadBundle(const char* filename)
+{
+ DataLoader* loader = DataLoader::GetLoader();
+ if (loader && filename && *filename) {
+ BYTE* buffer = 0;
+ loader->LoadBuffer(filename, buffer, true, true);
+ if (buffer && *buffer) {
+ char key[1024];
+ char val[2048];
+ char* p = (char*) buffer;
+ int s = 0, ik = 0, iv = 0;
+
+ key[0] = 0;
+ val[0] = 0;
+
+ while (*p) {
+ if (*p == '=') {
+ s = 1;
+ }
+ else if (*p == '\n' || *p == '\r') {
+ if (key[0] && val[0])
+ values.insert(Text(key).trim(), Text(val).trim());
+
+ ZeroMemory(key, 1024);
+ ZeroMemory(val, 2048);
+ s = 0;
+ ik = 0;
+ iv = 0;
+ }
+ else if (s == 0) {
+ if (!key[0]) {
+ if (*p == '#') {
+ s = -1; // comment
+ }
+ else if (!isspace(*p)) {
+ key[ik++] = *p;
+ }
+ }
+ else {
+ key[ik++] = *p;
+ }
+ }
+ else if (s == 1) {
+ if (!isspace(*p)) {
+ s = 2;
+ val[iv++] = *p;
+ }
+ }
+ else if (s == 2) {
+ val[iv++] = *p;
+ }
+
+ p++;
+ }
+
+ loader->ReleaseBuffer(buffer);
+ }
+ }
+}
diff --git a/Magic2/ContentBundle.h b/Magic2/ContentBundle.h
new file mode 100644
index 0000000..4848716
--- /dev/null
+++ b/Magic2/ContentBundle.h
@@ -0,0 +1,48 @@
+/* Project nGenEx
+ Destroyer Studios LLC
+ Copyright © 1997-2006. All Rights Reserved.
+
+ SUBSYSTEM: nGenEx.lib
+ FILE: ContentBundle.h
+ AUTHOR: John DiCamillo
+
+
+ OVERVIEW
+ ========
+ Chained collection of localized strings
+*/
+
+#ifndef ContentBundle_h
+#define ContentBundle_h
+
+#include "Types.h"
+#include "Dictionary.h"
+#include "Text.h"
+#include "Locale_ss.h"
+
+// +--------------------------------------------------------------------+
+
+class ContentBundle
+{
+public:
+ static const char* TYPENAME() { return "ContentBundle"; }
+
+ ContentBundle(const char* bundle, Locale* locale);
+ virtual ~ContentBundle();
+
+ int operator == (const ContentBundle& that) const { return this == &that; }
+
+ const Text& GetName() const { return name; }
+ Text GetText(const char* key) const;
+ bool IsLoaded() const { return !values.isEmpty(); }
+
+protected:
+ void LoadBundle(const char* filename);
+ Text FindFile(const char* bundle, Locale* locale);
+
+ Text name;
+ Dictionary<Text> values;
+};
+
+#endif ContentBundle_h
+
diff --git a/Magic2/Locale_ss.cpp b/Magic2/Locale_ss.cpp
new file mode 100644
index 0000000..9a87650
--- /dev/null
+++ b/Magic2/Locale_ss.cpp
@@ -0,0 +1,237 @@
+/* Project nGenEx
+ Destroyer Studios LLC
+ Copyright © 1997-2006. All Rights Reserved.
+
+ SUBSYSTEM: nGenEx.lib
+ FILE: Locale.cpp
+ AUTHOR: John DiCamillo
+
+
+ OVERVIEW
+ ========
+ 3D Locale (Polygon) Object
+*/
+
+#include "MemDebug.h"
+#include "Locale_ss.h"
+
+void Print(const char* fmt, ...);
+
+// +--------------------------------------------------------------------+
+
+static List<Locale> locales;
+
+// +--------------------------------------------------------------------+
+
+Locale::Locale(const char* l, const char* c, const char* v)
+{
+ ZeroMemory(this, sizeof(Locale));
+ if (l && *l) {
+ strncpy_s(language, l, 6);
+ char* p = language;
+ while (*p) {
+ *p = tolower(*p);
+ p++;
+ }
+ }
+
+ if (c && *c) {
+ strncpy_s(country, c, 6);
+ char* p = country;
+ while (*p) {
+ *p = toupper(*p);
+ p++;
+ }
+ }
+
+ if (v && *v) {
+ strncpy_s(variant, v, 6);
+ char* p = variant;
+ while (*p) {
+ *p = tolower(*p);
+ p++;
+ }
+ }
+
+ locales.append(this);
+}
+
+// +--------------------------------------------------------------------+
+
+Locale::~Locale()
+{
+ locales.remove(this);
+}
+
+// +--------------------------------------------------------------------+
+
+int
+Locale::operator == (const Locale& that) const
+{
+ if (this == &that) return 1;
+
+ return !_stricmp(language, that.language) &&
+ !_stricmp(country, that.country) &&
+ !_stricmp(variant, that.variant);
+}
+
+// +--------------------------------------------------------------------+
+
+Locale*
+Locale::ParseLocale(const char* str)
+{
+ if (str && *str) {
+ int i = 0;
+ char s1[4];
+ char s2[4];
+ char s3[4];
+
+ while (*str && *str != '_' && i < 3) {
+ s1[i] = *str++;
+ i++;
+ }
+ s1[i] = 0;
+ i = 0;
+
+ if (*str == '_')
+ str++;
+
+ while (*str && *str != '_' && i < 3) {
+ s2[i] = *str++;
+ i++;
+ }
+ s2[i] = 0;
+ i = 0;
+
+ if (*str == '_')
+ str++;
+
+ while (*str && *str != '_' && i < 3) {
+ s3[i] = *str++;
+ i++;
+ }
+ s3[i] = 0;
+ i = 0;
+
+ return CreateLocale(s1, s2, s3);
+ }
+
+ return 0;
+}
+
+// +--------------------------------------------------------------------+
+
+Locale*
+Locale::CreateLocale(const char* l, const char* c, const char* v)
+{
+ ListIter<Locale> iter = locales;
+ while (++iter) {
+ Locale* loc = iter.value();
+ if (!_stricmp(l, loc->GetLanguage())) {
+ if (c && *c) {
+ if (!_stricmp(c, loc->GetCountry())) {
+ if (v && *v) {
+ if (!_stricmp(v, loc->GetVariant())) {
+ return loc;
+ }
+ }
+ else {
+ return loc;
+ }
+ }
+ }
+ else {
+ return loc;
+ }
+ }
+ }
+
+ if (l[0]) {
+ if (c[0]) {
+ if (v[0]) {
+ return new(__FILE__,__LINE__) Locale(l, c, v);
+ }
+ return new(__FILE__,__LINE__) Locale(l, c);
+ }
+ return new(__FILE__,__LINE__) Locale(l);
+ }
+
+ return 0;
+}
+
+// +--------------------------------------------------------------------+
+
+const List<Locale>&
+Locale::GetAllLocales()
+{
+ return locales;
+}
+
+// +--------------------------------------------------------------------+
+
+const Text
+Locale::GetFullCode() const
+{
+ Text result = language;
+ if (*country) {
+ result.append("_");
+ result.append(country);
+
+ if (*variant) {
+ result.append("_");
+ result.append(variant);
+ }
+ }
+ return result;
+}
+
+// +--------------------------------------------------------------------+
+
+static const char* languages[] = {
+ "en", "English",
+ "fr", "French",
+ "de", "German",
+ "it", "Italian",
+ "pt", "Portuguese",
+ "ru", "Russian",
+ "es", "Spanish"
+};
+
+static const char* countries[] = {
+ "US", "USA",
+ "CA", "Canada",
+ "FR", "France",
+ "DE", "Germany",
+ "IT", "Italy",
+ "PT", "Portugal",
+ "RU", "Russia",
+ "ES", "Spain",
+ "UK", "United Kingdom"
+};
+
+const Text
+Locale::GetDisplayName() const
+{
+ Text result;
+ if (*language) {
+ for (int i = 0; i < 14; i += 2) {
+ if (!_stricmp(language, languages[i])) {
+ result = languages[i+1];
+ break;
+ }
+ }
+
+ if (*country) {
+ for (int i = 0; i < 18; i += 2) {
+ if (!_stricmp(country, countries[i])) {
+ result.append(" - ");
+ result.append(countries[i+1]);
+ break;
+ }
+ }
+ }
+
+ }
+ return result;
+}
+
diff --git a/Magic2/Locale_ss.h b/Magic2/Locale_ss.h
new file mode 100644
index 0000000..551c379
--- /dev/null
+++ b/Magic2/Locale_ss.h
@@ -0,0 +1,53 @@
+/* Project nGenEx
+ Destroyer Studios LLC
+ Copyright © 1997-2006. All Rights Reserved.
+
+ SUBSYSTEM: nGenEx.lib
+ FILE: Locale.h
+ AUTHOR: John DiCamillo
+
+
+ OVERVIEW
+ ========
+ Description of locale by ISO language, country, and variant
+*/
+
+#ifndef Locale_h
+#define Locale_h
+
+#include "List.h"
+#include "Text.h"
+
+// +--------------------------------------------------------------------+
+
+class Locale
+{
+public:
+ static const char* TYPENAME() { return "Locale"; }
+
+ Locale(const char* language, const char* country=0, const char* variant=0);
+ ~Locale();
+
+ int operator == (const Locale& that) const;
+
+ // Operations:
+ static const List<Locale>& GetAllLocales();
+ static Locale* ParseLocale(const char* str);
+
+ // Property accessors:
+ const char* GetLanguage() const { return language; }
+ const char* GetCountry() const { return country; }
+ const char* GetVariant() const { return variant; }
+ const Text GetFullCode() const;
+ const Text GetDisplayName() const;
+
+
+protected:
+ static Locale* CreateLocale(const char* language, const char* country=0, const char* variant=0);
+ char language[8];
+ char country[8];
+ char variant[8];
+};
+
+#endif Locale_h
+
diff --git a/Magic2/Magic.vcxproj b/Magic2/Magic.vcxproj
index 5acc1d6..874ac08 100644
--- a/Magic2/Magic.vcxproj
+++ b/Magic2/Magic.vcxproj
@@ -394,6 +394,7 @@
<ClCompile Include="..\nGenEx\D3DXImage.cpp" />
<ClCompile Include="..\nGenEx\DataLoader.cpp" />
<ClCompile Include="..\nGenEx\EditBox.cpp" />
+ <ClCompile Include="ContentBundle.cpp" />
<ClCompile Include="Editor.cpp" />
<ClCompile Include="..\nGenEx\Encrypt.cpp" />
<ClCompile Include="..\nGenEx\EventDispatch.cpp" />
@@ -418,6 +419,7 @@
<ClCompile Include="..\nGenEx\Light.cpp" />
<ClCompile Include="..\nGenEx\ListBox.cpp" />
<ClCompile Include="..\nGenEx\MachineInfo.cpp" />
+ <ClCompile Include="Locale_ss.cpp" />
<ClCompile Include="Magic.cpp" />
<ClCompile Include="MagicDoc.cpp" />
<ClCompile Include="MagicView.cpp" />
@@ -475,6 +477,7 @@
<ClCompile Include="..\Parser\Term.cpp" />
<ClCompile Include="..\nGenEx\TexDX9.cpp" />
<ClCompile Include="..\FoundationEx\Text.cpp" />
+ <ClCompile Include="TexCubeDX9.cpp" />
<ClCompile Include="TextureMapDialog.cpp" />
<ClCompile Include="Thumbnail.cpp" />
<ClCompile Include="..\Parser\Token.cpp" />
@@ -493,10 +496,12 @@
<ItemGroup>
<ClInclude Include="..\nGenEx\AviFile.h" />
<ClInclude Include="Command.h" />
+ <ClInclude Include="ContentBundle.h" />
<ClInclude Include="Editor.h" />
<ClInclude Include="Grid.h" />
<ClInclude Include="GridProps.h" />
<ClInclude Include="l3ds.h" />
+ <ClInclude Include="Locale_ss.h" />
<ClInclude Include="Magic.h" />
<ClInclude Include="MagicDoc.h" />
<ClInclude Include="MagicView.h" />
@@ -511,9 +516,11 @@
<ClInclude Include="Selector.h" />
<ClInclude Include="StdAfx.h" />
<ClInclude Include="SurfacePropertiesDialog.h" />
+ <ClInclude Include="TexCubeDX9.h" />
<ClInclude Include="TextureMapDialog.h" />
<ClInclude Include="Thumbnail.h" />
<ClInclude Include="UVMapView.h" />
+ <ClInclude Include="VideoDX9.h" />
</ItemGroup>
<ItemGroup>
<CustomBuild Include="res\Magic.ico" />
diff --git a/Magic2/Magic.vcxproj.filters b/Magic2/Magic.vcxproj.filters
index 70aae0d..7975525 100644
--- a/Magic2/Magic.vcxproj.filters
+++ b/Magic2/Magic.vcxproj.filters
@@ -309,6 +309,15 @@
<ClCompile Include="..\nGenEx\Window.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="TexCubeDX9.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="ContentBundle.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="Locale_ss.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Magic.rc">
@@ -385,6 +394,18 @@
<ClInclude Include="UVMapView.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="TexCubeDX9.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="VideoDX9.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="ContentBundle.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="Locale_ss.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="res\Magic.ico">
diff --git a/Magic2/TexCubeDX9.cpp b/Magic2/TexCubeDX9.cpp
new file mode 100644
index 0000000..c623215
--- /dev/null
+++ b/Magic2/TexCubeDX9.cpp
@@ -0,0 +1,120 @@
+/* Project nGenEx
+ Destroyer Studios LLC
+ Copyright © 1997-2004. All Rights Reserved.
+
+ SUBSYSTEM: nGenEx.lib
+ FILE: TexDX9.cpp
+ AUTHOR: John DiCamillo
+
+
+ OVERVIEW
+ ========
+ Direct3D Texture Cache
+*/
+
+#include "MemDebug.h"
+#include "TexCubeDX9.h"
+#include "VideoDX9.h"
+#include "Bitmap.h"
+#include "Color.h"
+
+// +--------------------------------------------------------------------+
+
+void Print(const char* fmt, ...);
+void VideoDX9Error(const char* msg, HRESULT err);
+
+#ifndef RELEASE
+#define RELEASE(x) if (x) { x->Release(); x=NULL; }
+#endif
+
+// +--------------------------------------------------------------------+
+
+TexCubeDX9::TexCubeDX9(VideoDX9* v)
+: video(v), texture(0)
+{
+ d3d = video->Direct3D();
+ d3ddevice = video->D3DDevice();
+
+ for (int i = 0; i < 6; i++) {
+ faces[i] = 0;
+ last_modified[i] = 0;
+ }
+}
+
+TexCubeDX9::~TexCubeDX9()
+{
+ RELEASE(texture);
+}
+
+// +--------------------------------------------------------------------+
+
+bool
+TexCubeDX9::LoadTexture(Bitmap* bmp, int face_index)
+{
+ if (!d3ddevice) return false;
+
+ if (faces[face_index] == bmp && last_modified[face_index] >= bmp->LastModified())
+ return true; // already loaded and hasn't been modified
+
+ HRESULT hr = D3D_OK;
+
+ // create the texture, if necessary
+ if (!texture) {
+ hr = d3ddevice->CreateCubeTexture(bmp->Width(),
+ 1, // one mip level
+ 0, // no specific usage
+ D3DFMT_A8R8G8B8, // format matching Color::rgba
+ D3DPOOL_MANAGED,
+ &texture,
+ 0);
+
+ if (FAILED(hr) || !texture) {
+ VideoDX9Error("LoadTexture - could not create cube texture", hr);
+ return false;
+ }
+ }
+
+ // lock the surface for writing
+ D3DLOCKED_RECT locked_rect;
+ D3DCUBEMAP_FACES face = (D3DCUBEMAP_FACES) face_index;
+ hr = texture->LockRect(face, 0, &locked_rect, 0, 0);
+
+ if (FAILED(hr)) {
+ VideoDX9Error("LoadTexture - could not lock texture surface", hr);
+ RELEASE(texture);
+ return false;
+ }
+
+ // load the bitmap into the texture surface
+ for (int i = 0; i < bmp->Height(); i++) {
+ BYTE* src = (BYTE*) (bmp->HiPixels() + i * bmp->Width());
+ BYTE* dst = (BYTE*) locked_rect.pBits + i * locked_rect.Pitch;
+
+ CopyMemory(dst, src, bmp->Width() * sizeof(Color));
+ }
+
+ // unlock the surface
+ texture->UnlockRect(face, 0);
+
+ faces[face_index] = bmp;
+ last_modified[face_index] = bmp->LastModified();
+
+ return true;
+}
+
+// +--------------------------------------------------------------------+
+
+IDirect3DCubeTexture9*
+TexCubeDX9::GetTexture()
+{
+ if (texture) {
+ // need to refresh anything?
+ for (int i = 0; i < 6; i++) {
+ if (faces[i] && last_modified[i] < faces[i]->LastModified()) {
+ LoadTexture(faces[i], i);
+ }
+ }
+ }
+
+ return texture;
+}
diff --git a/Magic2/TexCubeDX9.h b/Magic2/TexCubeDX9.h
new file mode 100644
index 0000000..686bcb9
--- /dev/null
+++ b/Magic2/TexCubeDX9.h
@@ -0,0 +1,49 @@
+/* Project nGenEx
+ Destroyer Studios LLC
+ Copyright © 1997-2006. All Rights Reserved.
+
+ SUBSYSTEM: nGenEx.lib
+ FILE: TexCubeDX9.h
+ AUTHOR: John DiCamillo
+
+
+ OVERVIEW
+ ========
+ Direct 3D Texture Cube for Env Mapping
+*/
+
+#ifndef TexCubeDX9_h
+#define TexCubeDX9_h
+
+#include "Bitmap.h"
+
+// +--------------------------------------------------------------------+
+
+class Video;
+class VideoDX9;
+class Bitmap;
+struct VD3D_texture_format;
+
+// +--------------------------------------------------------------------+
+
+class TexCubeDX9
+{
+public:
+ TexCubeDX9(VideoDX9* video);
+ virtual ~TexCubeDX9();
+
+ IDirect3DCubeTexture9* GetTexture();
+ bool LoadTexture(Bitmap* bmp, int face);
+
+private:
+ VideoDX9* video;
+ IDirect3D9* d3d;
+ IDirect3DDevice9* d3ddevice;
+
+ IDirect3DCubeTexture9* texture;
+ Bitmap* faces[6];
+ DWORD last_modified[6];
+};
+
+#endif // TexCubeDX9_h
+
diff --git a/Magic2/VideoDX9.h b/Magic2/VideoDX9.h
new file mode 100644
index 0000000..a9e0d6f
--- /dev/null
+++ b/Magic2/VideoDX9.h
@@ -0,0 +1,195 @@
+/* Project nGenEx
+ Destroyer Studios LLC
+ Copyright © 1997-2004. All Rights Reserved.
+
+ SUBSYSTEM: nGenEx.lib
+ FILE: VideoDX9.h
+ AUTHOR: John DiCamillo
+
+
+ OVERVIEW
+ ========
+ Direct3D and Direct3D Video classes for DirectX 7
+*/
+
+#ifndef VideoDX9_h
+#define VideoDX9_h
+
+#include "Video.h"
+#include "VideoSettings.h"
+#include "List.h"
+
+// +--------------------------------------------------------------------+
+
+class VideoDX9;
+class VideoDX9Enum;
+class VideoDX9VertexBuffer;
+class VideoDX9IndexBuffer;
+struct VideoDX9ScreenVertex;
+class Surface;
+class Segment;
+
+struct VideoDX9ScreenVertex;
+struct VideoDX9SolidVertex;
+struct VideoDX9LuminousVertex;
+struct VideoDX9LineVertex;
+
+
+// +--------------------------------------------------------------------+
+
+class VideoDX9 : public Video
+{
+public:
+ VideoDX9(const HWND& window, VideoSettings* vs);
+ virtual ~VideoDX9();
+
+ virtual const VideoSettings*
+ GetVideoSettings() const { return &video_settings; }
+ virtual bool SetVideoSettings(const VideoSettings* vs);
+
+ virtual bool SetBackgroundColor(Color c);
+ virtual bool SetGammaLevel(int g);
+ virtual bool SetObjTransform(const Matrix& o, const Point& l);
+
+ virtual bool SetupParams();
+ virtual bool Reset(const VideoSettings* vs);
+
+ virtual bool StartFrame();
+ virtual bool EndFrame();
+
+ virtual int Width() const { return width; }
+ virtual int Height() const { return height; }
+ virtual int Depth() const { return bpp; }
+
+ virtual void RecoverSurfaces();
+
+ virtual bool ClearAll();
+ virtual bool ClearDepthBuffer();
+ virtual bool Present();
+ virtual bool Pause();
+ virtual bool Resume();
+
+ virtual IDirect3D9* Direct3D() const { return d3d; }
+ virtual IDirect3DDevice9* D3DDevice() const { return d3ddevice; }
+ static IDirect3DDevice9* GetD3DDevice9();
+
+ virtual bool IsModeSupported(int width, int height, int bpp) const;
+ virtual bool IsHardware() const { return true; }
+ virtual int ZDepth() const { return zdepth; }
+ virtual DWORD VidMemFree() const;
+ virtual int D3DLevel() const { return 9; }
+ virtual int MaxTexSize() const;
+ virtual int MaxTexAspect() const;
+ virtual int GammaLevel() const { return gamma; }
+
+ virtual bool Capture(Bitmap& bmp);
+ virtual bool GetWindowRect(Rect& r);
+ virtual bool SetWindowRect(const Rect& r);
+ virtual bool SetViewport(int x, int y, int w, int h);
+ virtual bool SetCamera(const Camera* cam);
+ virtual bool SetEnvironment(Bitmap** faces);
+ virtual bool SetAmbient(Color c);
+ virtual bool SetLights(const List<Light>& lights);
+ virtual bool SetProjection(float fov,
+ float znear=1.0f,
+ float zfar=1.0e6f,
+ DWORD type=PROJECTION_PERSPECTIVE);
+ virtual bool SetRenderState(RENDER_STATE state, DWORD value);
+ virtual bool SetBlendType(int blend_type);
+
+ virtual bool DrawPolys(int npolys, Poly* p);
+ virtual bool DrawScreenPolys(int npolys, Poly* p, int blend=0);
+ virtual bool DrawSolid(Solid* s, DWORD blend_modes=0xf);
+ virtual bool DrawShadow(Solid* s, int nverts, Vec3* verts, bool vis=false);
+ virtual bool DrawLines(int nlines, Vec3* v, Color c, int blend=0);
+ virtual bool DrawScreenLines(int nlines, float* v, Color c, int blend=0);
+ virtual bool DrawPoints(VertexSet* v);
+ virtual bool DrawPolyOutline(Poly* p);
+ virtual bool UseMaterial(Material* m);
+
+ virtual bool UseXFont(const char* name, int size, bool b, bool i);
+ virtual bool DrawText(const char* text, int count, const Rect& rect,
+ DWORD format, Color c);
+
+ virtual void PreloadTexture(Bitmap* bmp);
+ virtual void PreloadSurface(Surface* s);
+ virtual void InvalidateCache();
+
+ static void CreateD3DMatrix(D3DMATRIX& result, const Matrix& m, const Point& p);
+ static void CreateD3DMatrix(D3DMATRIX& result, const Matrix& m, const Vec3& v);
+ static void CreateD3DMaterial(D3DMATERIAL9& result, const Material& mtl);
+
+private:
+ bool CreateBuffers();
+ bool DestroyBuffers();
+ bool PopulateScreenVerts(VertexSet* vset);
+ bool PrepareSurface(Surface* s);
+ bool DrawSegment(Segment* s);
+
+ int PrepareMaterial(Material* m);
+ bool SetupPass(int n);
+
+ HWND hwnd;
+ int width;
+ int height;
+ int bpp;
+ int gamma;
+ int zdepth;
+ Color background;
+
+ VideoDX9Enum* dx9enum;
+ VideoSettings video_settings;
+
+ IDirect3D9* d3d;
+ IDirect3DDevice9* d3ddevice;
+ D3DPRESENT_PARAMETERS d3dparams;
+ D3DSURFACE_DESC back_buffer_desc;
+ bool device_lost;
+
+ BYTE* surface;
+
+ DWORD texture_format[3];
+ D3DGAMMARAMP gamma_ramp;
+ double fade;
+
+ Rect rect;
+
+ IDirect3DVertexDeclaration9* vertex_declaration;
+ ID3DXEffect* magic_fx;
+ BYTE* magic_fx_code;
+ int magic_fx_code_len;
+
+ IDirect3DTexture9* current_texture;
+ int current_blend_state;
+ int scene_active;
+ DWORD render_state[RENDER_STATE_MAX];
+ Material* use_material;
+
+ Material* segment_material;
+ int strategy;
+ int passes;
+
+ ID3DXFont* d3dx_font;
+ char font_name[64];
+ int font_size;
+ bool font_bold;
+ bool font_ital;
+
+ Color ambient;
+ int nlights;
+
+ int first_vert;
+ int num_verts;
+
+ VideoDX9VertexBuffer* screen_vbuf;
+ VideoDX9IndexBuffer* screen_ibuf;
+ VideoDX9ScreenVertex* font_verts;
+ WORD* font_indices;
+ int font_nverts;
+
+ VideoDX9ScreenVertex* screen_line_verts;
+ VideoDX9LineVertex* line_verts;
+};
+
+#endif VideoDX9_h
+