pmc/main.cc
author Markus Bröker <mbroeker@largo.dyndns.tv>
Thu, 16 Apr 2009 12:49:13 +0200
changeset 57 7739518acafb
parent 54 c064ce9f40f5
child 65 76514757b0d6
permissions -rw-r--r--
duff.c: * Large String support added * parameter num renamed to len committer: Markus Bröker <mbroeker@largo.homelinux.org>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9
c3fecc82ade6 standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 4
diff changeset
     1
/**
c3fecc82ade6 standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 4
diff changeset
     2
 * test/demos/pmc/main.cc
c3fecc82ade6 standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 4
diff changeset
     3
 * Copyright (C) 2008 Markus Broeker
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     4
 */
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     5
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
     6
#include <surface.h>
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
     7
#include <rectangle.h>
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     8
#include <cube.h>
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     9
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    10
#include <cstdio>
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    11
#include <cstdlib>
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    12
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    13
#ifndef STEP
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    14
#define STEP 1
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    15
#endif
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    16
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    17
#define MAX 3
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    18
45
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents: 42
diff changeset
    19
using namespace algebra;
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents: 42
diff changeset
    20
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    21
int main (int argc, char **argv)
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    22
{
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    23
    Surface *surface;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    24
    SDL_Event event;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    25
    Drawable *d[MAX];
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    26
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    27
    int height;
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    28
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    29
    if (argc != 2) {
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    30
        fprintf (stderr, "Usage: %s <HEIGHT>\n", argv[0]);
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    31
        height = 250;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    32
    } else
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    33
        height = atoi (argv[1]);
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    34
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    35
    if ((height < 10) || (height >= 360))
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    36
        height = 200;
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    37
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    38
    Vector p1 (0, 0);
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    39
    Vector p2 (height, 0);
46
4b9e1ac40246 pmc: Screen Depth Fix: Paint on 8, 16 and 32 bpp
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 45
diff changeset
    40
    Vector p3 (height + 100, height + 100);
4b9e1ac40246 pmc: Screen Depth Fix: Paint on 8, 16 and 32 bpp
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 45
diff changeset
    41
    Vector p4 (100, height + 100);
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    42
46
4b9e1ac40246 pmc: Screen Depth Fix: Paint on 8, 16 and 32 bpp
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 45
diff changeset
    43
    surface = new Surface (1024, 768, 32);
4b9e1ac40246 pmc: Screen Depth Fix: Paint on 8, 16 and 32 bpp
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 45
diff changeset
    44
    SDL_WM_SetCaption ("Pimp my Cube", NULL);
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    45
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    46
    d[0] = new Rectangle (surface, p1, p2, p3, p4);
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    47
    d[1] = new Cube (surface);
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    48
    d[2] = new Cube (surface, p1, p2, p3, p4, height);
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    49
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    50
    bool running = true;
45
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents: 42
diff changeset
    51
    int i, x, y;
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    52
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    53
    x = y = 0;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    54
46
4b9e1ac40246 pmc: Screen Depth Fix: Paint on 8, 16 and 32 bpp
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 45
diff changeset
    55
    d[1]->move (Vector (3 * height, 25));
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    56
    d[2]->move (Vector (290, 0));
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    57
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    58
    while (running) {
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    59
        SDL_PollEvent (&event);
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    60
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    61
        if (event.type == SDL_QUIT)
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    62
            running = false;
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    63
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    64
        if (event.type == SDL_KEYDOWN) {
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    65
            surface->setColor (Surface::BLACK);
45
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents: 42
diff changeset
    66
            for (i = 0; i < MAX; i++)
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    67
                d[i]->show ();
46
4b9e1ac40246 pmc: Screen Depth Fix: Paint on 8, 16 and 32 bpp
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 45
diff changeset
    68
            surface->setColor (Surface::GREEN);
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    69
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    70
            switch (event.key.keysym.sym) {
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    71
            case SDLK_ESCAPE:
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    72
                running = false;
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    73
                break;
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    74
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    75
            case SDLK_UP:
45
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents: 42
diff changeset
    76
                for (i = 0; i < MAX; i++)
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    77
                    d[i]->move ((Vector (x, y - STEP)));
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    78
                break;
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    79
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    80
            case SDLK_DOWN:
45
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents: 42
diff changeset
    81
                for (i = 0; i < MAX; i++)
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    82
                    d[i]->move ((Vector (x, y + STEP)));
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    83
                break;
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    84
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    85
            case SDLK_LEFT:
45
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents: 42
diff changeset
    86
                for (i = 0; i < MAX; i++)
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    87
                    d[i]->move ((Vector (x - STEP, y)));
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    88
                break;
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    89
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    90
            case SDLK_RIGHT:
45
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents: 42
diff changeset
    91
                for (i = 0; i < MAX; i++)
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    92
                    d[i]->move ((Vector (x + STEP, y)));
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    93
                break;
54
c064ce9f40f5 Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 46
diff changeset
    94
c064ce9f40f5 Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 46
diff changeset
    95
            case SDLK_RETURN:
c064ce9f40f5 Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 46
diff changeset
    96
                fprintf (stderr, "Objects remaining: %d\n", surface->getInstances ());
c064ce9f40f5 Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 46
diff changeset
    97
                break;
c064ce9f40f5 Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 46
diff changeset
    98
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    99
            default:
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   100
                break;
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   101
            }
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   102
45
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents: 42
diff changeset
   103
            for (i = 0; i < MAX; i++) {
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
   104
                d[i]->show ();
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
   105
            }
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
   106
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
   107
            surface->flip ();
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   108
        }
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   109
    }
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   110
45
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents: 42
diff changeset
   111
    for (i = 0; i < MAX; i++)
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
   112
        delete d[i];
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   113
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
   114
    delete surface;
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   115
54
c064ce9f40f5 Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 46
diff changeset
   116
    /*
c064ce9f40f5 Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 46
diff changeset
   117
     * the remaining objects will be removed on exit
c064ce9f40f5 Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 46
diff changeset
   118
     */
c064ce9f40f5 Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 46
diff changeset
   119
    fprintf (stderr, "Objects remaining on exit: %d\n", refCounter);
c064ce9f40f5 Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 46
diff changeset
   120
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
   121
    return EXIT_SUCCESS;
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   122
}