Author Topic: New project?  (Read 22311 times)

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: New project?
« Reply #15 on: May 21, 2011, 05:44:11 PM »
I dont like data driven design.

Too bad. It's really cool and nice thing about it is that you don't have to be strictly data-driven in C++, because there is freedom to the amount of data vs. code. My type style classes are always almost a mixture of code and data arrays. It's reasonable to use code when only few of the items have a special feature, that way you don't have to write long lists of data for that particular feature.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: New project?
« Reply #16 on: May 21, 2011, 05:47:29 PM »
if you're bored with your current project you could make a small release, other people's perspective could help renew your interest.

Nice try:) I'm going to release Kaduria as soon as possible.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: New project?
« Reply #17 on: May 22, 2011, 07:36:01 AM »
It looks like I don't have OpenGL include files. Although it's only complaining about missing glaux.h. Now.. I tried to go OpenGL site and look for include files and library files to download. I failed in that task. Where the heck can you get OpenGL?

Edit: There is OpenGL installed already, but that glaux.h is missing. From some forum messages it's some kind of "older than heaven" part of experimental OpenGL that was once in time of dinosaurs.

And you can't download it anymore.

Edit2: Found it from some random site. But now I can't understand why project files are in such wacky location and I don't know how to set the output directory to compile the .exe in /source directory. I'm starting to think that I FUCKING QUIT! Fuck.
« Last Edit: May 22, 2011, 09:20:09 AM by Krice »

corremn

  • Rogueliker
  • ***
  • Posts: 700
  • Karma: +0/-0
  • SewerJack Extraordinaire
    • View Profile
    • Demise RogueLike Games
Re: New project?
« Reply #18 on: May 23, 2011, 12:29:43 AM »
Ok glaux.h was in my code base 10 years ago, I only removed it a couple of months ago, but not in TrollSlayer as that is 1 year old.  :(
I better remove if from all future sources.

The output file should compile in the Debug directory, and the "working directory" is set to the source directory.
Alternatively you can copy the "data" directory to the Debug directory.

As for GLAUX - even though it is too late do the following steps to remove its dependency.

  • Remove references to glaux.h and remove library glaux.lib from libraries.
  • Replace all function declarations in OpenGlTexture.h with the following line.

Code: [Select]
bool LoadGLTextures(unsigned number, const char * texture_filename);
  • Replace all code in OpenGlTexture.cpp with the following

Code: [Select]
#include "OpenGLTexture.h"

#include <stdio.h>
#include <fstream>


OpenGLTexture::OpenGLTexture(void)
{
}

OpenGLTexture::~OpenGLTexture(void)
{
}

/************************************************************************
                         REPLACEMENT FOR GLAUX
 ************************************************************************
This is not a full blown bitmap loader.  It is a quick and easy
way to replace the glAux dependant code in my older tutorials
with code that does not depend on the glAux library!

    This code only loads Truecolor Bitmap Images.  It will not load
8-bit bitmaps.  If you encounter a bitmap that will not load
use a program such as Irfanview to convert the bitmap to 24 bits.
 ************************************************************************/
bool OpenGLTexture::LoadGLTextures(unsigned number, const char * szFileName) // Load Bitmaps And Convert To Textures
{

bool Status = false;

HBITMAP hBMP; // Handle Of The Bitmap
BITMAP BMP; // Bitmap Structure

glGenTextures(1, &textures[number].texture);                        // Create The Texture

if(hBMP=(HBITMAP)LoadImage(GetModuleHandle(NULL), szFileName, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE ))
{
GetObject(hBMP, sizeof(BMP), &BMP); // Get The Object

Status=true; // Set The Status To true

glGenTextures(1, &textures[number].texture); // Create The Texture
//unsigned char* texels = new unsigned char[TextureImage[0]->sizeX*TextureImage[0]->sizeY*4];
unsigned char* texels = new  unsigned char[BMP.bmWidth*BMP.bmHeight*4];
unsigned char* outTexel = texels;
unsigned char* inTexel = (unsigned char*) BMP.bmBits;//TextureImage[0]->data;

//choose bottom left pixel of bitmap as colour for transparency
int trans_r = inTexel[0];
int trans_g = inTexel[1];
int trans_b = inTexel[2];

//convert RGB texture to RGBA texture
for( int y = 0; y <BMP.bmHeight; y++ )
{
for( int x = 0; x < BMP.bmWidth; x++, inTexel += 3, outTexel += 4 )
{
int r = inTexel[0];
int g = inTexel[1];
int b = inTexel[2];
int a;
//set alpha channel transparent when current pixel equals transparent colour
a = ((b == trans_b && g ==trans_g && r==trans_r) ? 0:255);

//set new alpha value
outTexel[0] = b;
outTexel[1] = g;
outTexel[2] = r;
outTexel[3] = a;
}

}

// Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D, textures[number].texture);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8,   BMP.bmWidth,           BMP.bmHeight,           0, GL_RGBA,    GL_UNSIGNED_BYTE, texels);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
textures[number].sizeX=BMP.bmWidth;
textures[number].sizeY=BMP.bmHeight;
delete[] texels;
}
DeleteObject(hBMP);

return Status; // Return The Status
}

  • Rebuild
« Last Edit: May 23, 2011, 01:52:05 AM by corremn »
corremn's Roguelikes. To admit defeat is to blaspheme against the Emperor.  Warhammer 40000 the Roguelike

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: New project?
« Reply #19 on: May 23, 2011, 06:47:40 AM »
I might try that. I have a short fuse:)

Well, after those changes and moving all data stuff to Debug I get this error:
First-chance exception at 0x7588b727 in TrollSlayer.exe: Microsoft C++ exception: std::runtime_error at memory location 0x0018f238

But it's only when I run the game from VS. What is this..

ps. The current changes list:

23.5.
- Item.cpp: removed #pragma warning(disable : 4786)
- Disabled Browse Information from project settings to speed up compiling
- InfoScreen::ShowAll removed "if (current_cell)" check which is always true and also a pointer
- Graphics::~Graphics added SDL_Quit for proper SDL exit in main() instead of using exit()
- Graphics::mainLoop removed panic_quit from SDL_QUIT event, instead return to the mainLoop for proper quit

- SDLSceneGen.cpp removed bool quitting;
- Graphics::mainLoop clean up
- changed Graphics::quit to panic_quit because of exit()
- Graphics::end changed to destructor of Graphics class
- removed double SDL_Init from main.cpp (was already in Graphics instance)

- ResistanceImmunityList::RemoveImmunity replaced for-loop with while to avoid invalid iterator erase
- BaseMonster::Serialize(std::ofstream &outStream): added missing delete[] buf;
- BaseMonster::Serialize(std::ifstream &inStream): delete buf; replaced with delete[] buf;
- removed WarlockException.h+cpp, they were not part of the project
- replaced OpenGLTexture::LoadGLTextures with new version

21.5.
- DungeonLevel.h & cpp: removed #pragma warning(disable : 4786)
- moved .txt files to new folder source/text (not options.txt)

- deleted empty New Text Document.txt from the source folder
- CellularAutomata.h: #define TILE_x changed to const int
- CellularAutomata.h: #define CA_x changed to enum Cellular_Automata_Type
- clean up of headers: replaced #pragma once with standards inclusion guards and removed VS precompiled headers
- changed #define NO_SPD_MOD 0 to const int
« Last Edit: May 23, 2011, 09:56:25 AM by Krice »

corremn

  • Rogueliker
  • ***
  • Posts: 700
  • Karma: +0/-0
  • SewerJack Extraordinaire
    • View Profile
    • Demise RogueLike Games
Re: New project?
« Reply #20 on: May 23, 2011, 11:27:51 AM »
Hmm good list of changes, if I knew you were going to be that thorough I would of had a quick skim over the source to tidy things up. I am sure if you run cppCheck you will get a lot of changes too.
I ignore bad code simply to produce output :)

Unsure about your error.  Are you saying that it is only from when you run the app from visual studio that it crashes? Can you run the Debug exe manually from the Debug directory?
My Debug build also creates some files in a directory called "Debug Files", the game crashes I think if it cannot find this directory.  You may need to copy that to the Debug Directory. Does the release work?

I would still set the working Directory to $(ProjectDir)/../../source
Set Project Properties / Debugging / Working Directory to $(ProjectDir)/../../source

Good Luck.

Well at least I have learned that I really should go over my code and clean it up, and make it much more exception safe, before I ever make a serious code release. 
corremn's Roguelikes. To admit defeat is to blaspheme against the Emperor.  Warhammer 40000 the Roguelike

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: New project?
« Reply #21 on: May 23, 2011, 02:15:42 PM »
Found three of those memory problems with CPPCheck... I moved all data files and folders to Debug, but I guess it still somehow points to /source when you run in VS. It could be nice to keep only source files in source, but I can't figure out how VS is running the .exe like it still was in /source.

corremn

  • Rogueliker
  • ***
  • Posts: 700
  • Karma: +0/-0
  • SewerJack Extraordinaire
    • View Profile
    • Demise RogueLike Games
Re: New project?
« Reply #22 on: May 23, 2011, 02:19:45 PM »
Yeah really should have a bin directory, where Trollslayer_d.exe is the debug build and TrollSlayer.exe is release.
Will look at this tomorrow.
corremn's Roguelikes. To admit defeat is to blaspheme against the Emperor.  Warhammer 40000 the Roguelike

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: New project?
« Reply #23 on: May 23, 2011, 02:21:40 PM »
Changed working directory to ($ProjectDir)/Debug (obviously..) and now it runs from VS.

Next I'm going to write a BMP import/export (with changes to output image size) for Brick Atelier to modify graphics.
« Last Edit: May 23, 2011, 02:27:10 PM by Krice »

scaught

  • Newcomer
  • Posts: 18
  • Karma: +0/-0
    • View Profile
Re: New project?
« Reply #24 on: May 24, 2011, 09:01:50 PM »
- clean up of headers: replaced #pragma once with standards inclusion guards and removed VS precompiled headers
Why?  #pragma once works in MSVC, gcc, icc, and every other major current compiler suite.  'Old style' include guards are prone to error and actually DO LESS than #pragma once does, unless you wrap the actual #include statement in them as well...and then calling it a clean up will really be a misnomer.

- changed #define NO_SPD_MOD 0 to const int
It probably doesn't matter for small projects, but changing constants that are never 'type-challenged' to be 'type-safe' can lead to code bloat.  Most compilers still allocate static data space per compile unit for named variables, even if in usage they're optimized away, whereas #define'd values are guaranteed to be "inlined" (for lack of a better term...).  Yes, it's only 4*CU bytes...it's nice having the luxury of it not mattering...


corremn

  • Rogueliker
  • ***
  • Posts: 700
  • Karma: +0/-0
  • SewerJack Extraordinaire
    • View Profile
    • Demise RogueLike Games
Re: New project?
« Reply #25 on: May 25, 2011, 12:23:29 AM »
#pramas vs include guards, much of a muchness, but in the world or roguelikes lets go with the standard.

- InfoScreen::ShowAll removed "if (current_cell)" check which is always true and also a pointer

I don't get it, current_cell can be a NULL reference. Hence the check. Well it really should throw an exception or assert.


- ResistanceImmunityList::RemoveImmunity replaced for-loop with while to avoid invalid iterator erase

Was that picked up by CppCheck or by you?  (this class is not used anyway, usually I have the iterator = the return from the erase() in such cases)

Probably should run the code over a code coverage program to determine unused code.  Know of any free ones for windows/c++?
corremn's Roguelikes. To admit defeat is to blaspheme against the Emperor.  Warhammer 40000 the Roguelike

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: New project?
« Reply #26 on: May 25, 2011, 07:30:38 AM »
I don't get it, current_cell can be a NULL reference. Hence the check.

All right. Let's add the check, but not like that. Anyway, current_cell is used before that check..

Quote
Probably should run the code over a code coverage program to determine unused code.  Know of any free ones for windows/c++?

I tried to find one of those, but they seem to be mainly commercial. New GCC is pretty good with special compiler flags. It's easy to get with Code::Blocks and you get a nice IDE with it.
« Last Edit: May 25, 2011, 07:32:30 AM by Krice »

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: New project?
« Reply #27 on: May 25, 2011, 07:36:37 AM »
Yes, it's only 4*CU bytes...it's nice having the luxury of it not mattering...

The best way is remove const ints from the header and possibly put them in a class or completely remove data like that. But const int is still better than #define.

TSMI

  • Rogueliker
  • ***
  • Posts: 65
  • Karma: +0/-0
    • View Profile
    • Email
Re: New project?
« Reply #28 on: June 01, 2011, 01:34:37 AM »
I'd love it if someone gave the old class Omega a less suicide inducing user interface.

http://www.alcyone.com/max/projects/omega/

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: New project?
« Reply #29 on: June 01, 2011, 07:10:11 AM »
I'd love it if someone gave the old class Omega a less suicide inducing user interface.

The source code is real old school C. Kind of cryptic, but maybe not impossible to do something for the UI.