Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Is this crap ?

Name: Anonymous 2009-12-03 16:15


// project created on 12/3/2009 at 8:23 PM
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>

int main(int argc, char *argv[]) {
    FILE *f;
    char s[255];
    char *bogo = NULL;
    char tmp[9];
    unsigned int val = 0;
    unsigned int i = 0;
    unsigned int c = 0;
    f = fopen("/proc/cpuinfo", "rt");
    if (f == NULL) {
        printf("We are probably on iShit or WinShit\n");
    } else {
        while (!feof(f)) {
            fgets(s, LINE_MAX, f);
            bogo = strstr(s, "bogomips");
            if (bogo != NULL) {
                i = c = val = 0;
                while (bogo[i] != ':') i++;
                i += 2;
                while (bogo[i] != '.') {
                    tmp[c] = ' ';
                    tmp[c] = bogo[i];
                    bogo[i] = ' ';
                    c++;
                    i++;
                }
                val = atoi(tmp);
                printf("%i\n", val);
            }
        }
        fclose(f);
    }
    printf("Done\n");
    return 0;
}

Name: Anonymous 2009-12-03 23:25

>>21
Oh god, is that what you thought? A timing loop needlessly (in modern times) drives CPU use up to 100%. No fun. Going to sleep lets other things use the CPU and generally conserves power.

Look, I'll actually try to be a bit helpful for real: http://www.coranac.com/tonc/text/toc.htm

Read that. Skim through the bits that don't apply but make sure you understand the "why" of all that stuff. Some of it is wildly specific, but keep in mind that this is for a piece of hardware designed to run video game code. It's also minimal enough to give you a good idea of what is going on at the hardware level, and how people solve these problems without  commercial APIs to do most of the work for them.

Would that work at a game running at like 60 FPS?
Yeah, if you want to sync to framerate it's the easiest case to code for.

Assuming double-buffering, do something like this in a loop: flush & flip video buffers, update game state, write to the unused buffer, wait for vsync, repeat. Just about any SDL type library should have something for waiting for vsync etc.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List