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 35 36 37 38 39 40 41 42 43 44 45 46 |
void CEngine::InitAll() { // this function is where you do all the initialization // for your game // create object and test for error if (DirectDrawCreateEx(NULL, (void **)&lpdd, IID_IDirectDraw7, NULL)!=DD_OK) PostMessage(main_window_handle, WM_DESTROY,0,0); // set cooperation level to windowed mode normal if (lpdd->SetCooperativeLevel(main_window_handle, DDSCL_ALLOWMODEX | DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT)!=DD_OK) PostMessage(main_window_handle, WM_DESTROY,0,0); // set the display mode if (lpdd->SetDisplayMode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_BPP,0,0)!=DD_OK) PostMessage(main_window_handle, WM_DESTROY,0,0); // Create the primary surface memset(&ddsd,0,sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); // set the flags to validate both the capabilities // field and the backbuffer count field ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; // we need to let dd know that we want a complex // flippable surface structure, set flags for that ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; // set the backbuffer count to 1 ddsd.dwBackBufferCount = 1; // create the primary surface lpdd->CreateSurface(&ddsd,&lpddsprimary,NULL); // query for the backbuffer or secondary surface // notice the use of ddscaps to indicate what // we are requesting ddscaps.dwCaps = DDSCAPS_BACKBUFFER; // get the surface lpddsprimary->GetAttachedSurface(&ddscaps,&lpddsback); } |
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 |
//Spielteil: void CEngine::MainGame() { // this is the workhorse of your game it will be called // continuously in real-time this is like main() in C // all the calls for you game go here! UCHAR *back_buffer = NULL, // used to draw *dest_ptr = NULL, // used in line by line copy *src_ptr = NULL; // " " // check of user is trying to exit if (KEY_DOWN(VK_ESCAPE) || KEY_DOWN(VK_SPACE)) PostMessage(main_window_handle, WM_DESTROY,0,0); // erase secondary back buffer memset(&ddsd,0,sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); // lock the secondary surface lpddsback->Lock(NULL,&ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,NULL); // get video pointer to secondary surface back_buffer = (UCHAR *)ddsd.lpSurface; // clear back buffer out // linear memory if (ddsd.lPitch == SCREEN_WIDTH) memset(back_buffer,0,SCREEN_WIDTH*SCREEN_HEIGHT); else { // non-linear memory // make copy of video pointer dest_ptr = back_buffer; // clear out memory one line at a time for (unsigned int y=0; y<SCREEN_HEIGHT; y++) { // clear nect line memset(dest_ptr,0,SCREEN_WIDTH); // advance pointer to next line dest_ptr+=ddsd.lPitch; } // end for y } // end else // perform game logic... // draw the next frame into the secondary back buffer // plot 5000 random pixels for (unsigned int index=0; index<5000; index++) { int x = rand()%SCREEN_WIDTH; int y = rand()%SCREEN_HEIGHT; UCHAR col = rand()%256; back_buffer[x+y*ddsd.lPitch] = col; } // end for index // unlock secondary buffer lpddsback->Unlock(NULL); // flip pages if(lpddsprimary->Flip(NULL, DDFLIP_WAIT)!=DD_OK) PostMessage(main_window_handle, WM_DESTROY,0,0); } |
Alter Hase
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#include <iostream> using namespace std; #include "CLog.h" int main() { CLog Logger; Logger.LogStart(); Logger.MakeEntry("--Alles funktioniert!!!--"); Logger.LogEnd(); system("PAUSE"); return EXIT_SUCCESS; } |
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 |
#ifndef CLog_H #define CLog_H // Standard-Includes #include <iostream> #include <fstream.h> /* ========================================================================================= ==Diese Klasse soll alle Fehler aufzeichnen!!! ==Das Funktioniert natürlich über ofstream!!! ========================================================================================= */ //Template für die Ausgaben Typen! template <class T> class CLog { public: CLog(); ~CLog(); //Standart Start und End Logs schreiben: void LogStart(); void LogEnd(); void MakeEntry(T LogEntry); private: //Name für die Datei: char* m_pFileName; static ofstream Log; }; #endif //CLog_H |
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 |
#include "CLog.h" ofstream CLog::Log; CLog::CLog() { } CLog::~CLog() { } void CLog::LogStart() { MakeEntry("--Log Beginnt!--"); } void CLog::MakeEntry(T LogEntry) { Log<<LogEntry<<"\n"; } void CLog::LogEnd() { MakeEntry("--Log Beendet!--"); } |
Werbeanzeige