au man... David wie kannst du nur....
???
Junge junge junge... guck dir lieber mal Singletons an, als staticclasses... Ist ja grausam... :kotz: :kotz:
Hier mal popeliges beispiel für SingleTons
|
Quellcode
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
// Dateiname: exDirect3D.h
// //////////////////////////////////////////////////////////////////////////////////
// Autor: Patrick Ullmann (c) by Xarent Interactive 2003
//
// Erstelldatum: 14.05.2003
// letzte Änderung: 14.05.2003 (Patrick) Datei wurde erstellt.
// //////////////////////////////////////////////////////////////////////////////////
// Info: Struktur für die Verwaltung von Direct3D9
// //////////////////////////////////////////////////////////////////////////////////
#ifndef _EXDIRECT3D_H_
#define _EXDIRECT3D_H_
// I N C L U D E S //////////////////////////////////////////////////////////////////
#include <windows.h>
#include <d3d9.h>
#include <d3dx9.h>
#include "exLog.h"
#include "exUtils.h"
// L I N K E R //////////////////////////////////////////////////////////////////////
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")
#pragma comment(lib, "dxguid.lib")
// D E F I N I T I O N E N - U N D - P R O T O T Y P E N ////////////////////////
const DWORD D3DFVF_UNTRANSFORMED = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1;
const DWORD D3DFVF_TRANSFORMED = D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1;
// S T R U K T U R E N //////////////////////////////////////////////////////////////
class __declspec(dllexport) exDirect3D
{
public:
~exDirect3D (void);
exResult init (HWND hwnd, int x, int y, int bpp, bool windowed);
exResult clear (D3DCOLOR color = 0xFF000000);
exResult begin (void);
exResult end (void);
exResult present (void);
static exDirect3D &getInstance (void) { return (m_Instance); }
private:
exDirect3D (void);
static exDirect3D m_Instance;
};
#endif
|
und die Cpp:
|
Quellcode
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
// Dateiname: exDirect3D.cpp
// //////////////////////////////////////////////////////////////////////////////////
// Autor: Patrick Ullmann (c) by Xarent Interactive 2003
//
// Erstelldatum: 14.05.2003
// letzte Änderung: 14.05.2003 (Patrick) Datei wurde erstellt.
// //////////////////////////////////////////////////////////////////////////////////
// Info: Struktur für die Verwaltung von Direct3D9
// //////////////////////////////////////////////////////////////////////////////////
// I N C L U D E S //////////////////////////////////////////////////////////////////
#include "exDirect3D.h"
// D E F I N I T I O N E N //////////////////////////////////////////////////////////
exDirect3D exDirect3D::m_Instance;
// F U N K T I O N E N //////////////////////////////////////////////////////////////
exDirect3D::exDirect3D (void)
{
this->m_d3d = NULL;
this->m_d3dDevice = NULL;
}
exDirect3D::~exDirect3D (void)
{
if (this->m_d3d != NULL)
{
this->m_d3d->Release();
this->m_d3d = NULL;
}
if (this->m_d3dDevice != NULL)
{
this->m_d3dDevice->Release();
this->m_d3dDevice = NULL;
}
}
exResult exDirect3D::init (HWND hwnd, int x, int y, int bpp, bool windowed)
{
EX_INFO ("Direct3D9 wird initzialisert...");
D3DFORMAT d3dfmt;
if (windowed)
{
d3dfmt = D3DFMT_UNKNOWN;
}
else
{
d3dfmt = D3DFMT_X8R8G8B8;
}
this->m_ScreenX = x;
this->m_ScreenY = y;
this->m_windowed = windowed;
// [...]
|
und so rufst benutzt du den singleton:
|
Quellcode
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
void initgame (void)
{
exDirect3D &Direct3D = exDirect3D::getInstance();
Direct3D.init (blablabla);
}
void rendergame (void)
{
exDirect3D &Direct3D = exDirect3D::getInstance();
Direct3D.begin ();
// [...]
Direct3D.end ();
Direct3D.render ();
}
|
Leute bitte bitte, benutzt wenn schon Singletons, weil die zum standard gehören und nicht gegen das OCP verstoßen und bitte bitte lasst diese #define definitionen für Integer oder popelige makros! benutzt const int wenn schon oder templates! Nur #define benutzen wenns nicht anders geht...