Skip to content

Commit

Permalink
Windows win32 code
Browse files Browse the repository at this point in the history
  • Loading branch information
DanBrooker committed Mar 27, 2012
1 parent 1c3c5bc commit 23eb75b
Show file tree
Hide file tree
Showing 24 changed files with 254 additions and 17 deletions.
9 changes: 8 additions & 1 deletion Code/DuneRL.cpp
Expand Up @@ -18,8 +18,11 @@
#include "DuneWorld.h"
#include "Map.h"

#ifdef _WIN32
#include "SDL.h"
#else
#include "SDL/SDL.h"
#include "SDL_image/SDL_image.h"
#endif
#include "SDL_OpenGL.h"
#include "SDLWindow.h"
#include "Window.h"
Expand Down Expand Up @@ -117,7 +120,11 @@ void DuneRL::init_world()

rnd = new Random(arc4random());

#ifdef _WIN32
sprite = new Sprite("D:\\Daniel\\Projects\\Github\\DuneRL\\Code\\Images\\tileset.png",16);
#else
sprite = new Sprite("DuneRL.app/Contents/Resources/tileset.png",16);
#endif
world = new DuneWorld();

Map *map = new Arrakis(worldSize);
Expand Down
8 changes: 7 additions & 1 deletion Code/Image.cpp
Expand Up @@ -8,21 +8,27 @@
*/

#include "Image.h"
#include "Stringer.h"

Image::Image(std::string filename)
{
GLTextureId = 0;
try
{
SDL_ClearError();
SDL_Surface* surface = IMG_Load(filename.c_str());


std::string error = std::string("SDL Error: ") + std::string(SDL_GetError());

glPixelStorei(GL_UNPACK_ALIGNMENT,4);
glGenTextures(1, &GLTextureId);
glBindTexture(GL_TEXTURE_2D, GLTextureId);
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,GL_REPLACE);



SDL_PixelFormat *format = surface->format;
if (format->Amask)
{
Expand Down
5 changes: 5 additions & 0 deletions Code/Image.h
Expand Up @@ -9,8 +9,13 @@
#ifndef IMAGE_H_INC
#define IMAGE_H_INC

#ifdef _WIN32
#include "SDL.h"
#include "SDL_image.h"
#else
#include "SDL/SDL.h"
#include "SDL_image/SDL_image.h"
#endif
#include "SDL_OpenGL.h"
#include <string>

Expand Down
3 changes: 3 additions & 0 deletions Code/LabelValue.h
Expand Up @@ -13,6 +13,9 @@
#include "Label.h"
#include <iostream>

#ifdef _WIN32
#define snprintf _snprintf
#endif

template < class T, class S >
class LabelValue : public Label
Expand Down
2 changes: 2 additions & 0 deletions Code/LightFilterShadow.cpp
Expand Up @@ -19,10 +19,12 @@
#include "DuneWorld.h"
#include "Map.h"

#ifndef _WIN32
inline double abs(double val)
{
return val > 0 ? val : -val;
}
#endif

double weighting(Point direction, int i, int j)
{
Expand Down
4 changes: 2 additions & 2 deletions Code/Lightmap.cpp
Expand Up @@ -211,7 +211,7 @@ WorldCoord Lightmap::local2world(LocalCoord l)
break;
case MapTypeWorldTile:
{
int realm = abs(y/size);
int realm = (int)abs((float)y/size);
bool flipped = realm %2;
if (y<0) {
//then flip again
Expand Down Expand Up @@ -278,7 +278,7 @@ bool Lightmap::pointInRange(Point a, Point b, int range)
else if(a.Y==b.Y)
return abs(a.X-b.X) <= range;
else
return pow(a.X-b.X,2) + pow(a.Y-b.Y,2) <= range*range;
return pow((float)a.X-b.X,2) + pow((float)a.Y-b.Y,2) <= range*range;
}

void Lightmap::calculate()
Expand Down
2 changes: 2 additions & 0 deletions Code/Monster.cpp
Expand Up @@ -34,6 +34,7 @@ Monster::Monster() : Object()
equipment = NULL;

behaviour = BehaviourDefensive;
sightMap = NULL;
}

Monster::Monster(Ascii *ascii) : Object(ascii)
Expand All @@ -51,6 +52,7 @@ Monster::Monster(Ascii *ascii) : Object(ascii)

behaviour = BehaviourDefensive;
// rangeFilter = NULL;
sightMap = NULL;
}

Monster::~Monster()
Expand Down
8 changes: 5 additions & 3 deletions Code/Perlin.cpp
Expand Up @@ -5,6 +5,8 @@

#include "Perlin.h"
#include "Heightmap.h"
#include "Random.h"
#define _USE_MATH_DEFINES
#include <math.h>

double Perlin::LinearInterpolate(double a, double b, double x)
Expand Down Expand Up @@ -151,7 +153,7 @@ double Perlin::PerlinNoise(double x,int octaves, double persistance)

for (int i = 0; i < octaves; i++)
{
double frequency = (double)pow(2, i);
double frequency = (double)pow(2.0f, i);
double amplitude = (double)pow(persistance, i);

total += InterpolateNoise(x * frequency) * amplitude;
Expand All @@ -165,7 +167,7 @@ double Perlin::PerlinNoise(double x, double y,int octaves, double persistance)

for (int i = 0; i < octaves; i++)
{
double frequency = (double)pow(2, i);
double frequency = (double)pow(2.0f, i);
double amplitude = (double)pow(persistance, i);

total += InterpolateNoise(x * frequency, y * frequency) * amplitude;
Expand All @@ -179,7 +181,7 @@ double Perlin::PerlinNoise(double x, double y, double z,int octaves, double pers

for (int i = 0; i < octaves; i++)
{
double frequency = (double)pow(2, i);
double frequency = (double)pow((float)2, i);
double amplitude = (double)pow(persistance, i);

total += InterpolateNoise(x * frequency, y * frequency, x * frequency) * amplitude;
Expand Down
17 changes: 16 additions & 1 deletion Code/Random.cpp
Expand Up @@ -29,4 +29,19 @@ float Random::getFloat()
double Random::getDouble()
{
return (*double_r)();
}
}

#ifdef _WIN32
#include <time.h>
int arc4random()
{
static bool once = false;
if(!once)
{
srand((unsigned)time(NULL));
once = true;
}
return rand();
}

#endif
4 changes: 4 additions & 0 deletions Code/Random.h
Expand Up @@ -30,4 +30,8 @@ class Random
double getDouble();
};

#ifdef _WIN32
int arc4random();
#endif

#endif /* RANDOM_H_INC */
2 changes: 1 addition & 1 deletion Code/RangeFilter.cpp
Expand Up @@ -27,7 +27,7 @@ RangeFilter::RangeFilter(LocalCoord destination) : LightFilter(),Display()
void RangeFilter::setDestinationPoint(LocalCoord destination)
{
//bresham line function to find valid points
double magnitude = sqrt((destination.Y*destination.Y) + (destination.X*destination.X));
double magnitude = sqrt((float)(destination.Y*destination.Y) + (float)(destination.X*destination.X));
if (magnitude>maxRange) {
return;
}
Expand Down
1 change: 1 addition & 0 deletions Code/Rect.cpp
Expand Up @@ -8,6 +8,7 @@

#include "Rect.h"
#include <cstdlib>
#include "Random.h"

Rect::Rect()
{
Expand Down
16 changes: 16 additions & 0 deletions Code/Roguelike.cpp
Expand Up @@ -57,11 +57,27 @@ int Roguelike::getCurrentTurn()

void Roguelike::log(std::string format, ...)
{
#ifdef _WIN32
//va_list args;
//int len = 0;
//char *buffer;
//char *format = (char*)malloc(f.size()+1 * sizeof(char) );
//strcpy(format,f.c_str());
//va_start(args,format);
//len = _vscprintf(format,args) + 1;
//buffer = (char*)malloc(len * sizeof(char) );
//vsprintf(buffer,format,args);
va_list args;
va_start(args, format);
std::string buffer;
DoFormatting(buffer, format, args);
#else
char *buffer;
va_list args;
va_start(args, format);
vasprintf(&buffer,format.c_str(), args);
va_end(args);
#endif

std::string entry = std::string(buffer);
int turn = world->getTurn();
Expand Down
8 changes: 7 additions & 1 deletion Code/Roguelike.h
Expand Up @@ -10,8 +10,13 @@
#ifndef ROGUELIKE_H_INC
#define ROGUELIKE_H_INC

#ifdef _WIN32
#include "SDL.h"
#include "SDL_image.h"
#else
#include "SDL/SDL.h"
#include "SDL_image/SDL_image.h"
#endif
#include "SDL_OpenGL.h"
#include "SDLWindow.h"
#include "Window.h"
Expand Down Expand Up @@ -64,8 +69,9 @@ class Roguelike
Window *getRootWindow();
World *getWorld();
Random *rnd;

void log(std::string format, ...);

static Roguelike *shared;
static bool dev;

Expand Down
4 changes: 4 additions & 0 deletions Code/SDLWindow.h
Expand Up @@ -7,7 +7,11 @@
*
*/

#ifdef _WIN32
#include "SDL.h"
#else
#include "SDL/SDL.h"
#endif

#ifndef SDLWINDOW_H_INC
#define SDLWINDOW_H_INC
Expand Down

0 comments on commit 23eb75b

Please sign in to comment.