Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
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 |
class Eingabe; class Geraet { friend Eingabe; public: Geraet* next,*previous; LPDIRECTINPUTDEVICE8 g_lpDIDevice; GUID Type; Geraet(LPDIRECTINPUT8, GUID, HWND); ~Geraet(); void* Getdata(void* zeiger=NULL); }; class Eingabe { private: LPDIRECTINPUT8 g_lpDI; Geraet* first; public: Geraet* Geraeterfragen(GUID, HWND); void ReleaseGeraet(Geraet*); Eingabe(HINSTANCE); ~Eingabe(); }; |
C-/C++-Quelltext |
|
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
// Eingabe.cpp: Implementierung der Klasse Eingabe. // ////////////////////////////////////////////////////////////////////// #include "Engine.h" ////////////////////////////////////////////////////////////////////// // Konstruktion/Destruktion ////////////////////////////////////////////////////////////////////// Eingabe::Eingabe(HINSTANCE hinst) { this->first=NULL; if(DI_OK != DirectInput8Create(hinst, 0x0800, IID_IDirectInput8, (void**)&g_lpDI, NULL)) this->g_lpDI=NULL; }; Eingabe::~Eingabe() { while(this->first!=NULL) first->~Geraet(); if(this->g_lpDI!=NULL) this->g_lpDI->Release(); } Geraet* Eingabe::Geraeterfragen(GUID DevType, HWND Window) { if(this->g_lpDI==NULL) return NULL; for(Geraet* temp= this->first; temp!=NULL; temp=temp->next) if(temp->Type == DevType) return temp; if(first!=NULL) { first->previous=new(Geraet)(this->g_lpDI, DevType, Window); if(first->previous->g_lpDIDevice==NULL) first->previous->~Geraet(); first->previous->next=first; first=first->previous; return first; } else { first=new(Geraet)(this->g_lpDI, DevType, Window); if(first->g_lpDIDevice==NULL) first->~Geraet(); return first; } } void Eingabe::ReleaseGeraet(Geraet* geraet) { if(geraet==first) first=NULL; if(geraet->next!=NULL) geraet->next->previous=geraet->previous; if(geraet->previous!=NULL) geraet->previous->next=geraet->next; geraet->~Geraet(); } Geraet::Geraet(LPDIRECTINPUT8 g_lpDI, GUID DevType, HWND Window) { this->g_lpDIDevice=NULL; this->Type=DevType; if(DI_OK != g_lpDI->CreateDevice(DevType, &this->g_lpDIDevice, NULL)) { this->~Geraet(); return;} if(this->Type==GUID_SysKeyboard) if(DI_OK != this->g_lpDIDevice->SetDataFormat(&c_dfDIKeyboard)) { this->~Geraet(); return;} if(this->Type==GUID_SysMouse) if(DI_OK != this->g_lpDIDevice->SetDataFormat(&c_dfDIMouse2)) { this->~Geraet(); return;} if(DI_OK != this->g_lpDIDevice->SetCooperativeLevel(Window, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND)) //DISCL_EXCLUSIVE| { this->~Geraet(); return;} this->g_lpDIDevice->Acquire(); return; } Geraet::~Geraet() { if(this->g_lpDIDevice) { this->g_lpDIDevice->Unacquire(); this->g_lpDIDevice->Release(); } this->g_lpDIDevice=NULL; } void* Geraet::Getdata(void* Zeiger) { if(this->g_lpDIDevice==NULL) return NULL; if(DIERR_INPUTLOST==g_lpDIDevice->Poll()) g_lpDIDevice->Acquire(); if(Zeiger==NULL) { if(this->Type==GUID_SysKeyboard) Zeiger=new(char[256]); if(this->Type==GUID_SysMouse) Zeiger=new(DIMOUSESTATE2); } // if(DIERR_NOTINITIALIZED==this->g_lpDIDevice->GetDeviceState(256, Zeiger)) // return Zeiger; HRESULT hr=this->g_lpDIDevice->GetDeviceState(256, Zeiger); switch(hr)// seltsma keine fehlermeldung sit es { case DIERR_INPUTLOST : break; case DIERR_INVALIDPARAM : break; case DIERR_NOTACQUIRED : break; case DIERR_NOTINITIALIZED : break; case E_PENDING : break; } if(DI_OK != this->g_lpDIDevice->Acquire()) return NULL; if(DI_OK==this->g_lpDIDevice->GetDeviceState(sizeof Zeiger, Zeiger)) return Zeiger; return NULL; } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
/////////////////////////////////////////////////////////////////////////////////////// // EINGABE /////////////////////////////////////////////////////////////////////////////////////// Geraet keyboard=spiel.pEingabe->Geraeterfragen(GUID_SysKeyboard, spiel.pDirektX->PresentParams.hDeviceWindow); char Keyboard[256]; if(keyboard!=NULL) keyboard->Getdata(Keyboard); if(Keyboard[DIK_UP] & 0x80) Modells->Movement(myVektor(0,0,1)); if(Keyboard[DIK_DOWN] & 0x80) Modells->Movement(myVektor(0,0,-1)); if(Keyboard[DIK_BACK] & 0x80) Modells->SetMovement(myVektor(0,0,0)); |
Werbeanzeige