Changes:
* added Makefile (windows part not yet finished)
* splitted array.cpp in a header file -> include/array.h
* sources/main.cpp only uses include/array.h
1 parent f5aa952 commit 4b3fe7167724a4cfd1a7ad3a37e465ce59b8fc20
@ajaggi ajaggi authored on 26 Dec 2005
Showing 4 changed files
View
42
Makefile 0 → 100755
OBJDIR := obj
SRCDIR := sources
INCLUDEDIR := include
BINDIR := bin
 
DEBUG := yes
 
ifdef COMSPEC
# windows
CXX := C:/g++
CXXFLAGS := -Wall -I$(INCLUDEDIR)
LIBS :=
RM := rm
PROGNAME := cg.exe
else
# better than windows
CXX := g++
CXXFLAGS := -DUNIX -Wall `sdl-config --cflags` -I$(INCLUDEDIR)
LIBS := `sdl-config --libs` -lGL -lGLU
RM := rm -f
PROGNAME := cg
endif
 
ifeq "$(DEBUG)" "yes"
CXXFLAGS := $(CXXFLAGS) -DDEBUG
endif
 
all: $(OBJDIR)/main.o $(OBJDIR)/array.o
$(CXX) $(CXXFLAGS) $(LIBS) $(OBJDIR)/array.o $(OBJDIR)/main.o -o $(BINDIR)/$(PROGNAME)
 
$(OBJDIR)/main.o: $(SRCDIR)/main.cpp
$(CXX) $(CXXFLAGS) -c $(SRCDIR)/main.cpp -o $(OBJDIR)/main.o
 
$(OBJDIR)/array.o: $(SRCDIR)/array.cpp $(INCLUDEDIR)/array.h
$(CXX) $(CXXFLAGS) -c $(SRCDIR)/array.cpp -o $(OBJDIR)/array.o
 
run:
$(BINDIR)/$(PROGNAME)
clean:
$(RM) $(OBJDIR)/*
$(RM) $(BINDIR)/*
View
25
include/array.h 0 → 100755
class Array {
private:
int _size;
int _current;
int _stacksize;
void** _data;
public:
Array();
Array(Array* oa);
void setPos(int np);
int pos();
int length();
void reset();
void* current();
void* next();
void push(void* elem);
void* pop();
void* get(int p);
void set(int p, void* ne);
void clear();
void operator+=(void *ne);
void*& operator[](int p);
~Array();
};
View
286
sources/array.cpp
#include <assert.h>
 
class Array {
private:
int _size;
int _current;
int _stacksize;
void** _data;
public:
Array() {
_size = 0;
_current = 0;
_stacksize = 0;
#include "array.h"
 
Array::Array() {
_size = 0;
_current = 0;
_stacksize = 0;
}
 
Array::Array(Array* oa) {
_size = 0;
_current = 0;
_stacksize = 0;
void* telem;
int tc = oa->pos();
oa->reset();
 
while ( (telem = oa->next()) ) {
push(telem);
}
 
Array(Array* oa) {
_size = 0;
_current = 0;
_stacksize = 0;
void* telem;
int tc = oa->pos();
oa->reset();
oa->setPos(tc);
 
while ( (telem = oa->next()) ) {
push(telem);
}
 
void Array::setPos(int np) {
_current = np;
}
 
int Array::pos() {
return _current;
}
 
int Array::length() {
return _size;
}
 
void Array::reset() {
_current = 0;
}
 
void* Array::current() {
if ( _current < _size ) {
return _data[_current];
} else {
return 0;
}
}
 
void* Array::next() {
if ( _current < _size ) {
_current++;
return _data[_current-1];
} else {
return 0;
}
}
 
void Array::push(void* elem) {
if ( _size >= _stacksize ) {
_stacksize = _stacksize + 3;
void** tdat = new void*[_stacksize];
 
for ( int i = 0; i < _size; i++ ) {
tdat[i] = _data[i];
}
 
oa->setPos(tc);
 
if ( _size > 0 ) {
delete[] _data;
}
_data = tdat;
}
 
void setPos(int np) {
_current = np;
_data[_size] = elem;
_size++;
}
 
void* Array::pop() {
_size--;
if ( _current == _size ) {
_current = _size-1;
}
return _data[_size];
}
 
int pos() {
return _current;
}
void* Array::get(int p) {
assert(p>=0);
assert(p<_size);
return _data[p];
}
 
int length() {
return _size;
}
void Array::set(int p, void* ne) {
assert(p>=0);
assert(p<_size);
_data[p] = ne;
}
 
void reset() {
_current = 0;
}
void Array::clear() {
_size = 0;
_current = 0;
_stacksize = 0;
delete[] _data;
}
 
void* current() {
if ( _current < _size ) {
return _data[_current];
} else {
return 0;
}
}
void Array::operator+=(void* ne) {
push(ne);
}
 
void* next() {
if ( _current < _size ) {
_current++;
return _data[_current-1];
} else {
return 0;
}
}
void*& Array::operator[](int p) {
assert(p>=0);
assert(p<_size);
return _data[p];
}
 
void push(void* elem) {
if ( _size >= _stacksize ) {
_stacksize = _stacksize + 3;
void** tdat = new void*[_stacksize];
Array::~Array() {
delete[] _data;
}
for ( int i = 0; i < _size; i++ ) {
tdat[i] = _data[i];
}
 
if ( _size > 0 ) {
delete[] _data;
}
_data = tdat;
}
 
_data[_size] = elem;
_size++;
}
 
void* pop() {
_size--;
if ( _current == _size ) {
_current = _size-1;
}
return _data[_size];
}
 
void* get(int p) {
assert(p>=0);
assert(p<_size);
return _data[p];
}
 
void set(int p, void* ne) {
assert(p>=0);
assert(p<_size);
_data[p] = ne;
}
 
void clear() {
_size = 0;
_current = 0;
_stacksize = 0;
delete[] _data;
}
 
void operator+=(void* ne) {
push(ne);
}
 
void*& operator[](int p) {
assert(p>=0);
assert(p<_size);
return _data[p];
}
 
~Array() {
delete[] _data;
}
};
View
10
sources/main.cpp
//////////////
// #INCLUDE //
//////////////
 
#ifdef WIN32
#ifndef UNIX
#include <windows.h> // Only required under Windows :-D
#endif
 
#include <SDL.h> // This file import the SDL inteface
//#include <SDL.h> // This file import the SDL inteface
#include <SDL/SDL.h> // This file import the SDL inteface
#include <GL/gl.h> // This file import the OpenGL interface
#include <GL/glu.h> // This file offers some OpenGL-related utilities
 
#include <fstream>
 
#include <math.h>
 
#ifdef WIN32
#ifndef UNIX
/////////////
// #PRAGMA //
/////////////
// Visual Studio specific: you can import libraries directly by
#pragma comment(lib, "sdl.lib")
#pragma comment(lib, "sdlmain.lib")
#endif
 
#include "array.cpp"
#include "array.h"
 
using namespace std;
 
/////////////
#define WINDOW_ZETADEPTH 24 // z-buffer depth (in bits)
 
#define SURFACE_COUNT 6
#define PI 3.14159265f
 
#define DEBUG
 
int debugct = 0;
int firstprint = 1;