Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexAkulov committed Apr 2, 2016
0 parents commit fd480d3
Show file tree
Hide file tree
Showing 204 changed files with 15,695 additions and 0 deletions.
68 changes: 68 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
########################################
#
# build parameters
#
########################################

# installation prefix
PREFIX=/usr/local

########################################
#
# do not modify rest of this file
#
########################################

OPTIMIZE=#-O6 -march=pentium4 -mfpmath=sse -fomit-frame-pointer -funroll-loops
PROFILER=#-pg
DEBUG=#-ggdb
CXXFLAGS=-pipe -Wall $(OPTIMIZE) $(DEBUG) `sdl-config --cflags` -DPREFIX=L\"$(PREFIX)\" $(PROFILER)
LNFLAGS=-pipe -lSDL_ttf -lfreetype `sdl-config --libs` -lz -lSDL_mixer $(PROFILER)
INSTALL=install

TARGET=einstein

SOURCES=puzgen.cpp main.cpp screen.cpp resources.cpp utils.cpp game.cpp \
widgets.cpp iconset.cpp puzzle.cpp rules.cpp \
verthins.cpp random.cpp horhints.cpp menu.cpp font.cpp \
conf.cpp storage.cpp tablestorage.cpp regstorage.cpp \
topscores.cpp opensave.cpp descr.cpp options.cpp messages.cpp \
formatter.cpp buffer.cpp unicode.cpp convert.cpp table.cpp \
i18n.cpp lexal.cpp streams.cpp tokenizer.cpp sound.cpp
OBJECTS=puzgen.o main.o screen.o resources.o utils.o game.o \
widgets.o iconset.o puzzle.o rules.o verthints.o random.o \
horhints.o menu.o font.o conf.o storage.o options.o \
tablestorage.o regstorage.o topscores.o opensave.o descr.o \
messages.o formatter.o buffer.o unicode.o convert.o table.o \
i18n.o lexal.o streams.o tokenizer.o sound.o
HEADERS=screen.h main.h exceptions.h resources.h utils.h \
widgets.h iconset.h puzzle.h verthints.h random.h horhints.h \
font.h conf.h storage.h tablestorage.h regstorage.h \
topscores.h opensave.h game.h descr.h options.h messages.h \
foramtter.h buffer.h visitor.h unicode.h convert.h table.h \
i18n.h lexal.h streams.h tokenizer.h sound.h

.cpp.o:
$(CXX) $(CXXFLAGS) -c $<

all: $(TARGET)


$(TARGET): $(OBJECTS)
$(CXX) $(LNFLAGS) $(OBJECTS) -o $(TARGET)

clean:
rm -f $(OBJECTS) core* *core $(TARGET) *~

depend:
@makedepend $(SOURCES) 2> /dev/null

run: $(TARGET)
./$(TARGET)

install: $(TARGET)
$(INSTALL) -s -D $(TARGET) $(PREFIX)/bin/$(TARGET)
$(INSTALL) -D einstein.res $(PREFIX)/share/einstein/res/einstein.res

# DO NOT DELETE THIS LINE -- make depend depends on it.

63 changes: 63 additions & 0 deletions Makefile.macosx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
########################################
#
# build parameters
#
########################################

# installation prefix
PREFIX=/usr/local

########################################
#
# do not modify rest of this file
#
########################################

OPTIMIZE=#-O6 -march=pentium4 -mfpmath=sse -fomit-frame-pointer -funroll-loops
PROFILER=#-pg
DEBUG=-ggdb
CXXFLAGS=-pipe -Wall $(OPTIMIZE) $(DEBUG) -I/Library/Frameworks/SDL.framework/Headers/ -I/Library/Frameworks/SDL_ttf.framework/Headers/ -I/Library/Frameworks/SDL_mixer.framework/Headers/ -DPREFIX=L\"$(PREFIX)\" $(PROFILER)
LNFLAGS=-pipe -framework Cocoa -framework SDL_ttf -framework SDL -framework SDL_mixer -lSDLmain -lz $(PROFILER)

TARGET=einstein

SOURCES=puzgen.cpp main.cpp screen.cpp resources.cpp utils.cpp game.cpp \
widgets.cpp iconset.cpp puzzle.cpp rules.cpp \
verthins.cpp random.cpp horhints.cpp menu.cpp font.cpp \
conf.cpp storage.cpp tablestorage.cpp regstorage.cpp \
topscores.cpp opensave.cpp descr.cpp options.cpp messages.cpp \
formatter.cpp buffer.cpp unicode.cpp convert.cpp table.cpp \
i18n.cpp lexal.cpp streams.cpp tokenizer.cpp sound.cpp
OBJECTS=puzgen.o main.o screen.o resources.o utils.o game.o \
widgets.o iconset.o puzzle.o rules.o verthints.o random.o \
horhints.o menu.o font.o conf.o storage.o options.o \
tablestorage.o regstorage.o topscores.o opensave.o descr.o \
messages.o formatter.o buffer.o unicode.o convert.o table.o \
i18n.o lexal.o streams.o tokenizer.o sound.o
HEADERS=screen.h main.h exceptions.h resources.h utils.h \
widgets.h iconset.h puzzle.h verthints.h random.h horhints.h \
font.h conf.h storage.h tablestorage.h regstorage.h \
topscores.h opensave.h game.h descr.h options.h messages.h \
foramtter.h buffer.h visitor.h unicode.h convert.h table.h \
i18n.h lexal.h streams.h tokenizer.h sound.h

.cpp.o:
$(CXX) $(CXXFLAGS) -c $<

all: $(TARGET)


$(TARGET): $(OBJECTS)
$(CXX) $(LNFLAGS) $(OBJECTS) -o $(TARGET)

clean:
rm -f $(OBJECTS) core* *core $(TARGET) *~

depend:
@makedepend $(SOURCES) 2> /dev/null

run: $(TARGET)
./$(TARGET)

# DO NOT DELETE

49 changes: 49 additions & 0 deletions Makefile.win
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
OPTIMIZE=-O3 #-march=pentium4 -mfpmath=sse -fomit-frame-pointer -funroll-loops
DEBUG=#-ggdb
CXXFLAGS=-Wall $(OPTIMIZE) $(DEBUG) -Ic:/mingw/include/sdl -mwindows
LNFLAGS=-lmingw32 -lSDLmain -mwindows
LIBS=-lmingw32 -lSDLmain -lSDL_ttf -lSDL -lfreetype -lz -lSDL_mixer

TARGET=einstein

SOURCES=puzgen.cpp main.cpp screen.cpp resources.cpp utils.cpp game.cpp \
widgets.cpp iconset.cpp puzzle.cpp rules.cpp \
verthins.cpp random.cpp horhints.cpp menu.cpp font.cpp \
conf.cpp storage.cpp tablestorage.cpp regstorage.cpp \
topscores.cpp opensave.cpp descr.cpp options.cpp messages.cpp \
formatter.cpp buffer.cpp unicode.cpp convert.cpp table.cpp \
i18n.cpp lexal.cpp streams.cpp tokenizer.cpp sound.cpp
OBJECTS=puzgen.o main.o screen.o resources.o utils.o game.o \
widgets.o iconset.o puzzle.o rules.o verthints.o random.o \
horhints.o menu.o font.o conf.o storage.o options.o \
tablestorage.o regstorage.o topscores.o opensave.o descr.o \
messages.o formatter.o buffer.o unicode.o convert.o table.o \
i18n.o lexal.o streams.o tokenizer.o sound.o
HEADERS=screen.h main.h exceptions.h resources.h utils.h \
widgets.h iconset.h puzzle.h verthints.h random.h horhints.h \
font.h conf.h storage.h tablestorage.h regstorage.h \
topscores.h opensave.h game.h descr.h options.h messages.h \
foramtter.h buffer.h visitor.h unicode.h convert.h table.h \
i18n.h lexal.h streams.h tokenizer.h sound.h

.cpp.o:
$(CXX) $(CXXFLAGS) -c $<

all: $(TARGET)


$(TARGET): $(OBJECTS)
$(CXX) $(LNFLAGS) $(OBJECTS) $(LIBS) -o $(TARGET)

clean:
del $(TARGET).exe
del *.o

depend:
@makedepend $(SOURCES) 2> /dev/null

run: $(TARGET)
./$(TARGET)

# DO NOT DELETE

3 changes: 3 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

To build and install einstein edit Makefile and run `make install` as root.

104 changes: 104 additions & 0 deletions buffer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#include "buffer.h"
#include <string.h>
#include "exceptions.h"
#include "unicode.h"


Buffer::Buffer(int sz, int alloc)
{
allocated = alloc;
size = sz;
if (size > allocated)
allocated = size;
if (allocated < 1024)
allocated = 1024;
data = malloc(allocated);
if (! data)
throw Exception(L"Error allocating memory for Buffer");
}

Buffer::~Buffer()
{
free(data);
}

void Buffer::setSize(size_t sz)
{
if (sz > allocated) {
int newAl = allocated + sz + 1024;
void *d = realloc(data, newAl);
if (! d)
throw Exception(L"Error expanding buffer memory");
data = d;
allocated = newAl;
}

size = sz;
}

size_t Buffer::getSize()
{
return size;
}

size_t Buffer::getAllocated()
{
return allocated;
}

void* Buffer::getData()
{
return data;
}


void Buffer::gotoPos(int offset)
{
currentPos = offset;
}


size_t Buffer::putData(const unsigned char *d, size_t length)
{
if (size < currentPos + length)
setSize(currentPos + length);
memcpy((unsigned char*)data + currentPos, d, length);
currentPos += length;
return length;
}


size_t Buffer::putInteger(int v)
{
unsigned char b[4];
int i, ib;

for (i = 0; i < 4; i++) {
ib = v & 0xFF;
v = v >> 8;
b[i] = ib;
}

return putData(b, 4);
}


size_t Buffer::putUtf8(const std::wstring &string)
{
std::string s(toUtf8(string));
putInteger(s.length());
putData((const unsigned char*)s.c_str(), s.length());
return 4 + s.length();
}


size_t Buffer::putByte(unsigned char value)
{
if (size < (size_t)currentPos + 1)
setSize(currentPos + 1);
((unsigned char*)data)[currentPos] = value;
currentPos++;
return 1;
}


79 changes: 79 additions & 0 deletions buffer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#ifndef __BUFFER_H__
#define __BUFFER_H__


#include <stdlib.h>
#include <string>


/// Dynamic growing buffer
class Buffer
{
private:
size_t size;
size_t allocated;
void *data;
int currentPos;

public:
/// Create buffer
/// \param size initial size of buffer
/// \param allocated bytes to allocate
Buffer(int size=0, int allocated=1024);

~Buffer();

public:
/// Set buffer size, expands memory if needed
/// \param size new size
void setSize(size_t size);

/// Get current size of buffer
size_t getSize();

/// Get actual bytes used by buffer
size_t getAllocated();

/// Get pointer to data
void* getData();

public:
/// Move pointer to specified position.
/// \param offset offset from buffer start
void gotoPos(int offset);

/// Add data to buffer and advance current position by data length.
/// Grow buffer if needed.
/// \param data pointer to data
/// \param length data size.
size_t putData(const unsigned char *data, size_t length);

/// Add data to buffer and advance current position by data length.
/// Grow buffer if needed.
/// \param data pointer to data
/// \param length data size.
size_t putData(const char *data, size_t length) {
return putData((const unsigned char*)data, length);
};

/// Add integer to buffer and advance current position by 4.
/// Grow buffer if needed.
/// \param value value to add.
size_t putInteger(int value);

/// Add string to buffer encoded in UTF-8 and advance current
/// position by string length. String stored prefixed by
/// string length.
/// Grow buffer if needed.
/// \param string value to add.
size_t putUtf8(const std::wstring &string);

/// Add byte to buffer and advance current position by 1.
/// Grow buffer if needed.
/// \param value value to add.
size_t putByte(unsigned char value);
};


#endif

Loading

0 comments on commit fd480d3

Please sign in to comment.