• Advertisement


  • Content count

  • Joined

  • Last visited

Everything posted by simon10k

  1. Computing PI

    I know PI is approx 3.142... but how did "they" work that out? I don't think it was with a string and a ruler, unless it was a very big circle. I heard somewhere that there was a computer program working out the defininate value of PI, that it is a very long number and doesn't seem to have an end. How could I conjure up something in C++ to compute the value of PI without a constant, or just typing it -for learning purposes.
  2. File input and output, help plz

    You can also write the size of the vector to the file so you know how many elements to read.
  3. A C++ Timer?

    I think this will help you. timer.h #ifndef _TIMER_ #define _TIMER_ #include <ctime> class Timer { clock_t counter; public: Timer(): counter(0) {}; bool elasped(clock_t ms) { clock_t tick = std::clock(); if(tick - counter >= ms) { counter = tick; return true; } return false; } }; #endif main.cpp #include <iostream> #include "timer.h" int main() { Timer timer; while(true) { if(timer.elasped(1000)) std::cout << "ding!\n"; } }
  4. visual C 8 game loop

    My game loop looks like this MSG msg = {}; while(msg.message != WM_QUIT) { if(PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg); else RunFrame(); }
  5. Could someone show me an example of how to resize the client area of the window to a certain width and height? Using the WS_OVERLAPPEDWINDOW flag.
  6. Looking for a Good Win32 compiler

    I think you can only run VC++ Express on the computer you installed it on, I'm not sure though, I'm going by the fact that my VC++ Express programs don't run at college. And when I uninstalled VC++ Express the programs stop running too.
  7. VC++ 2005 Express Problem - Platform SDK Install

    Quote:Original post by pulpfist Suddenly you go quiet :D I guess we finally nailed it... I think that was his suicide note [grin]
  8. How do I find the frequency of the cpu so I can convert the rdtsc into milliseconds.
  9. Frames Per Second question

    We get an approximation, but then again, your probably right about the GPU.
  10. rdtsc help

    I was just wondering if this is the correct way to use the rdtsc unsigned __int64 get_cpu_tick() { DWORD dwLow, dwHigh; __asm { rdtsc mov dwLow, eax mov dwHigh, edx } return ((unsigned __int64) dwHigh << 32 | dwLow); } or am I missing something? Thanks. ~edit~ I found another function, unsigned __int64 __rdtsc(void); Which does what I need, another question, does QueryPerformanceFrequency() return the frequency of the processsor?
  11. rdtsc help

    Another thing, can I convert the rdtsc into ms?
  12. Frames Per Second question

    I think vsync is good, but I like to be able to use the frame_rate as a benchmark, so I don't include the flip/present() in my time tests so my code might look like int start = clock(); RunFrame(); int frame_rate = clock() - start; Text("frame rate: ", frame_rate); Flip();
  13. You can make a call to timeBeginPeriod at the start of your application, and a call, with the same parameter to timeEndPeriod at the end of your application. int main() { timeBeginPeriod(1); //use timers timeEndPeriod(1); } As I understand it.
  14. The timeBeginPeriod function sets the minimum timer resolution for an application or device driver. timePeriodBegin(1); Sleep(1); timeEndPeriod(1);
  15. win32 app

    You can put #undef UNICODE at the top of your source files -i.e. before <windows.h>, which is good for converting an old project to work on the new compiler.
  16. animation?

    I just used DirectDraw for loading a bitmap into surface memory, the logic is in C++. You should be able to see how the concept works though, which is based on the array of RECT's. I think you can do the same with D3D9 surfaces.
  17. animation?

    Here is something for you to chew on. [smile] char* bmp_file; int bmp_width, bmp_height; IDirectDrawSurface7* lpdds; RECT* tile_rect; int tile_width; int tile_height; int tile_rows; int tile_cols; int tile_num; void tileset::Load(char* arg_file, int arg_tilewidth, int arg_tileheight) { //Load bitmap bmp_file = arg_file; lpdds = ddgfx::LoadBitmapSurface(bmp_file); //Get bitmap size DDSURFACEDESC2 ddsd = {0}; ddsd.dwSize = sizeof(ddsd); lpdds->GetSurfaceDesc(&ddsd); bmp_width = ddsd.dwWidth; bmp_height = ddsd.dwHeight; //Compute rows and collums tile_width = arg_tilewidth; tile_height = arg_tileheight; tile_cols = bmp_width / tile_width; tile_rows = bmp_height / tile_height; //Allocate an array of RECT's tile_rect = new RECT[tile_rows * tile_cols]; tile_num = 0; //Set the rects to the correct position for(int y=0; y<tile_rows; y++) for(int x=0; x<tile_cols; x++) { tile_rect[tile_num].left = x*tile_width; tile_rect[tile_num].top = y*tile_height; tile_rect[tile_num].right = tile_rect[tile_num].left + tile_width; tile_rect[tile_num].bottom = tile_rect[tile_num].top + tile_height; ++tile_num; } } void tileset::Unload() { delete[] tile_rect; lpdds->Release(); lpdds = 0; } void tileset::Draw(int index, int x, int y) { RECT src = tile_rect[index]; RECT dst = { x, y, x + tile_width, y + tile_height}; lpddsback->Blt(&dst, lpdds, &src, DDBLT_WAIT, 0); }
  18. why use struct?

    Quote:Original post by DevLiquidKnight I think structs might have less overhead or memory use age. It might depend on the compiler though, don't quote me on that though I am purely speculating. I will quote you [smile], you might make people paranoid about using a struct. Quote:Bjarne Stroustrup, TC++PL Special Edition By definition, a struct is a class in which all members are public; that is, struct s { ... is simply shorthand for class s { public: ...
  19. animation?

    The way I handle bitmap animation is to load a bitmap into a surface then calculate the rectangle position of each tile, each tile is arranged side by side in a bitmap file with no seperator lines. The initialization of the tileset needs to know the width and height of tiles, I let the caller of the init function provide these. The idea is to get an array of RECT's where 0 is the first image and the last is sizeof(rect)-1, [0][1][2][3] [4][5][6][7] etc... Then you can have a function void Draw(int index, int x, int y) { Blt(&backbuffer, &rect[index], x, y); } //a call might look like this Draw(player.get_frame(), player.x, player.y); I have code that shows how this works on my other computer, and I will post later.
  20. binary, bitwise etc

    This site explains binary operations quite well. -C/C++.
  21. What is the best line drawing algorithm for drawing lines in any direction?
  22. Best Line Drawing Algorithm

    As in for a fast software algorithm. Or, what algorithms do modern video cards use?
  23. Global Timer

    Stops the header being included more than once. #ifndef MY_GUARD #define MY_GUARD [header file] #endif
  24. Global Timer

    Are you using include guards?
  25. Global Timer

    "support.h" extern unsigned long g_DeltaTimer; "some_file.cpp" unsigned long g_DeltaTimer; Would that fix it?
  • Advertisement