pmc/main.cc
author Markus Bröker <mbroeker@largo.dyndns.tv>
Fri, 19 Nov 2010 12:23:24 +0100
changeset 158 2cddd4d26139
parent 129 d82830a449a9
permissions -rw-r--r--
removed unnecessary #includes 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
/**
77
49e0babccb23 HEADER TAGS
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 65
diff changeset
     2
 * pmc/main.cc
9
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
65
76514757b0d6 GNU Indent cannot handle C++ Source Files...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 54
diff changeset
     6
#include <surface.hpp>
76514757b0d6 GNU Indent cannot handle C++ Source Files...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 54
diff changeset
     7
#include <rectangle.hpp>
76514757b0d6 GNU Indent cannot handle C++ Source Files...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 54
diff changeset
     8
#include <cube.hpp>
4
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
129
d82830a449a9 PMC goes fullscreen ...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 77
diff changeset
    17
#define MAX 1
42
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
129
d82830a449a9 PMC goes fullscreen ...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 77
diff changeset
    29
    surface = new Surface (0, 0, 32);
d82830a449a9 PMC goes fullscreen ...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 77
diff changeset
    30
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    31
    if (argc != 2) {
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    32
        fprintf (stderr, "Usage: %s <HEIGHT>\n", argv[0]);
129
d82830a449a9 PMC goes fullscreen ...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 77
diff changeset
    33
        height = surface->getHeight () / 2;
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    34
    } else
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    35
        height = atoi (argv[1]);
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    36
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    37
    Vector p1 (0, 0);
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    38
    Vector p2 (height, 0);
129
d82830a449a9 PMC goes fullscreen ...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 77
diff changeset
    39
    Vector p3 (height, height);
d82830a449a9 PMC goes fullscreen ...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 77
diff changeset
    40
    Vector p4 (0, height);
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    41
46
4b9e1ac40246 pmc: Screen Depth Fix: Paint on 8, 16 and 32 bpp
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 45
diff changeset
    42
    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
    43
129
d82830a449a9 PMC goes fullscreen ...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 77
diff changeset
    44
    d[0] = 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
    45
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    46
    bool running = true;
45
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents: 42
diff changeset
    47
    int i, x, y;
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    48
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    49
    x = y = 0;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    50
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    51
    while (running) {
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    52
        SDL_PollEvent (&event);
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    53
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    54
        if (event.type == SDL_QUIT)
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    55
            running = false;
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    56
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    57
        if (event.type == SDL_KEYDOWN) {
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    58
            surface->setColor (Surface::BLACK);
45
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents: 42
diff changeset
    59
            for (i = 0; i < MAX; i++)
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    60
                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
    61
            surface->setColor (Surface::GREEN);
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    62
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    63
            switch (event.key.keysym.sym) {
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    64
            case SDLK_ESCAPE:
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    65
                running = false;
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    66
                break;
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    67
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    68
            case SDLK_UP:
45
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents: 42
diff changeset
    69
                for (i = 0; i < MAX; i++)
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    70
                    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
    71
                break;
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    72
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    73
            case SDLK_DOWN:
45
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents: 42
diff changeset
    74
                for (i = 0; i < MAX; i++)
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    75
                    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
    76
                break;
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    77
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    78
            case SDLK_LEFT:
45
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents: 42
diff changeset
    79
                for (i = 0; i < MAX; i++)
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    80
                    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
    81
                break;
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    82
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    83
            case SDLK_RIGHT:
45
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents: 42
diff changeset
    84
                for (i = 0; i < MAX; i++)
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    85
                    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
    86
                break;
54
c064ce9f40f5 Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 46
diff changeset
    87
c064ce9f40f5 Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 46
diff changeset
    88
            case SDLK_RETURN:
c064ce9f40f5 Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 46
diff changeset
    89
                fprintf (stderr, "Objects remaining: %d\n", surface->getInstances ());
c064ce9f40f5 Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 46
diff changeset
    90
                break;
c064ce9f40f5 Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 46
diff changeset
    91
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    92
            default:
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    93
                break;
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    94
            }
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    95
45
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents: 42
diff changeset
    96
            for (i = 0; i < MAX; i++) {
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    97
                d[i]->show ();
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    98
            }
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    99
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
   100
            surface->flip ();
4
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
    }
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   103
45
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents: 42
diff changeset
   104
    for (i = 0; i < MAX; i++)
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
   105
        delete d[i];
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   106
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
   107
    delete surface;
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   108
54
c064ce9f40f5 Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 46
diff changeset
   109
    /*
c064ce9f40f5 Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 46
diff changeset
   110
     * the remaining objects will be removed on exit
c064ce9f40f5 Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 46
diff changeset
   111
     */
c064ce9f40f5 Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 46
diff changeset
   112
    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
   113
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
   114
    return EXIT_SUCCESS;
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   115
}