Welcome Guest ( Log In | Register )

 

SMTWTFS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

Request A Topic!
Want me to blog about something? Perhaps a language? A piece of software? A specific topic? Let me know! Even guests can post here on my blog!

If you would like to request a topic, please post a comment here and I'll get on it right away! smile.gif

Search My Blog


Categories

3 Pages V  1 2 3 >
 | Category: General
entry 24 Sep, 2009 - 11:44 AM
While I'm certainly not FoxPro's biggest fan, I have to admit that it's a pretty good language. It's so easy to use, and you can produce great solutions in such a short amount of time. It's hard to find proper tutorials, and there's only really one site which offers great support.

Yeah, so it has VB-esque syntax. No, it doesn't always do what you expect it to do. But as a whole, what does?

I'd like to make VFP a little more known around DIC. We didn't even have a C# forum (or was it the C# tutorial section?) about a year ago, but look at where PsychoCoder has gotten us with that.

So yeah. After almost a year of having to use the language day in/day out, I'm starting to like it, regardless of the shroud of darkness covering it.

What are your thoughts on FoxPro? Do you consider it a dying language? I reckon a lot of my readers haven't even used it, some may not have even heard of it! D:

 | Category: General
entry 15 Sep, 2009 - 10:24 AM
Been a while.

This is such a difficult decision. I think it probably is for a lot of programmers. This is more of a personal entry than most, more just explaining my thought process on the whole path that I can't decide to take. confused.gif

It's a decision I'm still failing to make. I think about it every day, yet I still can't come to a decision. I know I'm much better at software development, but game development is one of those things that every kid dreams of.

Usually, when I make any sort of attempt at game programming, I decide on a project that's WAY too big for me, and I just end up giving up halfway through. I lose motivation and interest, because I feel like I'm getting nowhere, and I always end up being stubborn and working on it alone.

I guess I need to learn to be more of a team player. I'm obsessive-compulsive about my code. It's not exactly pretty, but it's something I take pride in and don't like other people tampering with.

My plan of action is to finish my snippet manager, which has been slow in any development since that ridiculously early release. Life gets pretty hectic and it's hard to find the time and motivation to continue such a large project in my free time, without earning a penny from it.

When that gets done, I'm going to move on to a new game project. And this time, I'm not gonna be so stubborn. I'll find myself a team, and we'll actually make something together. Perhaps if I have a team, I'll be more motivated so as not to let them down.

If anyone else has faced this decision, how did you choose?

Same applies to web dev vs software vs games, I guess. Though I know I'm not gonna put my main focus in web development. I just don't enjoy it as much as I do in programming other things, for some reason. confused.gif

 | Category: Side Scroller Engine
entry 21 Jun, 2009 - 06:42 AM
Okay, so I decided on a quick side project to my MMORPG engine - a 2D side scroller engine. I've spent three days on this, and so far, I have:

- sprite animation
- maps with automated collision detection
- shooting
- AI enemies that follow and attack (though they're a little bit thick)
- scrolling maps, but without *only* moving the map (if you know what I mean?) player moves freely, map scrolls when necessary

Not bad for three days work, eh? smile.gif

I've got a small video demo available, which I'm updating regularly. It can be found at the following address:
http://gabehabe.com/sidescroller/demo.avi

The graphics are absolutely crap, but they do help to demonstrate the functionality quite well.

The engine is unique [I think] in that it requires absolutely no programming to create a game with it. So, [when it's finally complete] you'll be able to simply drop your maps in a certain folder and it'll read them systematically, detect collision points on the images, and play them one by one. You'll even be able to add video files as cutscenes between levels, and sound - all read in dynamically at runtime.

 | Category: Project Euler
entry 12 Jun, 2009 - 07:24 AM
WARNING : CONTAINS SPOILERS! smile.gif

Decided to blog about some of the more interesting project euler tasks here. Could lead to some interesting discussion on algorithms, too. w00t.gif

I won't be blogging about every problem I work on, and I don't spend too much time on there, but it's nice to try your hand at a challenge. smile.gif

The least efficient part of this code is rotate_int which I threw together in about 5 minutes. I'm happy though, since it works and I can solve the problem in ~3.5 seconds using this program. (2.5s of which is used to determine all primes below 1,000,000)
Here's the code for the rotate_int function:
cpp
int rotate_int(int x, int rotations) {
vector<int> vec;
ostringstream ostr;
ostr << x;
string str = ostr.str();
for(unsigned int i = 0; i < str.length(); i++) {
vec.push_back(str[i]-48);
}
rotate(vec.begin(), vec.begin()+rotations, vec.end());
int mul = 1;
for(unsigned int i = 1; i < vec.size(); i++) {
mul *= 10;
}
x = 0;
for(unsigned int i = 0; i < vec.size(); i++) {
x += vec[i] * mul;
mul /= 10;
}
return x;
}
Told you it was inefficient! tongue.gif

The rest of the program is really just a wrapper for that prime bitset.

The final product is this:
cpp
/* WARNING - CONTAINS SPOILERS!
* Project Euler - Problem 35
* Circular primes
* http://projecteuler.net/index.php?section=problems&id=35
* Author: Danny Battison
*/
#include <iostream>
#include <bitset>
#include <cmath>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

const int MAX = 1000000;

void output(bitset<MAX> primes) {
for(int i = 0; i < MAX; i++) {
if(primes[i] == 1) {
cout << i << " ";
}
}
}

int get_nth_prime(int n, bitset<MAX> primes) {
int count = 0;
for(int i = 2; i < MAX; i++) {
if(primes[i]) {
count++;
} if(count == n) {
return i;
}
}
return 0; // could not find
}

int rotate_int(int x, int rotations) {
vector<int> vec;
ostringstream ostr;
ostr << x;
string str = ostr.str();
for(unsigned int i = 0; i < str.length(); i++) {
vec.push_back(str[i]-48);
}
rotate(vec.begin(), vec.begin()+rotations, vec.end());
int mul = 1;
for(unsigned int i = 1; i < vec.size(); i++) {
mul *= 10;
}
x = 0;
for(unsigned int i = 0; i < vec.size(); i++) {
x += vec[i] * mul;
mul /= 10;
}
return x;
}

int main() {
bitset <MAX> primes;
for(int i = 2; i < MAX; i++) {
primes[i] = 1;
}
// quick sieve of eratosthenes -- start it off
int sieve[] = {2,3,5,7}; // give it a few primes to start with
for(int mul = 0; mul < 4; mul++) {
for(int i = 1; i < MAX; i++) {
if(i % sieve[mul] == 0 && i != sieve[mul]) {
primes[i] = 0;
}
}
}

// by now, we have a list of primes with some larger numbers still left
// in order to remove those, we now need to run through primes and
// make sure to remove multiples of primes up to sqrt(MAX)
for(int i = 2; i < sqrt(MAX); i++) {
if(primes[i]) {
for(int j = i+1; j < MAX; j++) {
if(j % i == 0) {
primes[j] = 0;
}
}
}
}

// this section takes approx 1s - could be reduced GREATLY
// but I'm lazy.
ostringstream ostr;
int len;
bool t = 0;
int count = 0;
int x;
for(int i = 1; i < MAX; i++) {
if(primes[i]) {
ostr.str("");
ostr << i;
len = ostr.str().length();
for(int j = 0; j < len; j++) {
x = rotate_int(i, j);
t = primes[x];
if(!t) break;
}
if(t) {
count++;
}
}
}cout << count;

return 0;
}

 | Category: C++
entry 12 Jun, 2009 - 07:04 AM
Quick entry, posting it for safe keeping. smile.gif

I've already found this useful in a few of the problems over at project euler so I figured I'd share it. Quick primes! I actually wrote this a few days ago in response to NickDMax's thread (check it out, it's pretty interesting), before I realised what he was trying to do. (I was hasty!)

This program runs in silly time, something like a tenth of a second. Not bad for finding all primes up to 100,000 and finding the nth prime number, huh? wink2.gif
cpp
/*
* A fast method of producing a table of primes
* using a bitset
* Author: Danny Battison
*/

#include <iostream>
#include <bitset>
#include <cmath>

using namespace std;

#define MAX 100000

void output(bitset<MAX> primes) {
for(int i = 0; i < MAX; i++) {
if(primes[i] == 1) {
cout << i << " ";
}
}
}

int get_nth_prime(int n, bitset<MAX> primes) {
int count = 0;
for(int i = 2; i < MAX; i++) {
if(primes[i]) {
count++;
} if(count == n) {
return i;
}
}
return 0; // could not find
}

int main() {
bitset <MAX> primes;
for(int i = 1; i < MAX; i++) {
primes[i] = 1;
}
// quick sieve of eratosthenes -- start it off
int sieve[] = {2,3,5,7}; // give it a few primes to start with
for(int mul = 0; mul < 4; mul++) {
for(int i = 1; i < MAX; i++) {
if(i % sieve[mul] == 0 && i != sieve[mul]) {
primes[i] = 0;
}
}
}

// by now, we have a list of primes with some larger numbers still left
// in order to remove those, we now need to run through primes and
// make sure to remove multiples of primes up to sqrt(MAX)
for(int i = 2; i < sqrt(MAX); i++) {
if(primes[i]) {
for(int j = i+1; j < MAX; j++) {
if(j % i == 0) {
primes[j] = 0;
}
}
}
}

cout << get_nth_prime(1000, primes);

return 0;
}

 | Category: MMORPG Engine
entry 11 Jun, 2009 - 09:52 AM
So, I'm finally uploading the source. It's a little buggy (still) but it should be stable. (Memory and CPU usage seem pretty stable too)

I'm intrigued to see if anyone can build it for their OS, or what errors they come across. I've included the Windows DLLs, and all references are relative (I hope) to the project, so *hopefully* it should build without problems. I've never released the code for a full project like this before, so let's see how it goes.

I don't know how other operating systems use dependencies like Windows DLLs, but I know they'll require some other stuff - no idea what.happy.gif

To those of you willing to try to build a release for your OS - thank you. :') if you could email me the build (gabehabe@gmail.com), I'll upload it to SourceForge and credit you for your contribution.

Please note I'm not looking for any help on the project, I'm determined to do it by myself. That said, I'm open to suggestions on how to improve it. smile.gif

download now

 | Category: Game Programming
entry 10 Jun, 2009 - 10:18 AM
Not gonna give it all away yet, it needs an extreme cleanup. My code is a total mess! smile.gif

Instead, I'm gonna give you a few tasters. Ready? Good.

First off, a little collision detection for that map. This took a while to perfect, I gotta admit. In fact to be honest, there's still a lot of room for improvement. smile.gif

My code is a fucking disgrace to mankind here, please don't hate me for it!
cpp
int map::collision_check_bottom(int x, int y) {
x+=SPRITE_WIDTH;
vector<SDL_Rect>::iterator it;
vector<object*>::iterator it2;
vector<exit*>::iterator it3;
int i = 0;

for(it3 = this->exits.begin(); it3 != this->exits.end(); ++it3, i++) {
if(((*it3)->offset.y+(*it3)->offset.h>y-9&&(*it3)->offset.y+(*it3)->offset.h<y+6)&&((*it3)->offset.x<x&&(*it3)->offset.x+(*it3)->offset.w+SPRITE_WIDTH>x))return INT_MAX-i;
}

for(it = this->off_limits.begin(); it != this->off_limits.end(); ++it) {
if((it->y+it->h>y-9&&it->y+it->h<y+6)&&(it->x<x&&it->x+it->w+SPRITE_WIDTH>x))return -1;
}

i = 0;
for(it2 = this->objects.begin(); it2 != this->objects.end(); ++it2, i++) {
if(((*it2)->offset.y+(*it2)->offset.h>y-9&&(*it2)->offset.y+(*it2)->offset.h<y+6)&&((*it2)->offset.x<x&&(*it2)->offset.x+(*it2)->offset.w+SPRITE_WIDTH>x))return i;
}

return -2;
}


Aaaaannndddd, another piece of the engine. This is the player movement function, which utilises that nasty looking collision detection. smile.gif
cpp
bool player::move(int direction) { // 1=up, 2=down, 3=left, 4=right
int movement = this->running ? (VELOCITY*2)-3 : VELOCITY;
int x = 0;
switch(direction) {
case 1:
x = this->the_map->collision_check_bottom(this->_x, this->_y-movement+SPRITE_HEIGHT-5);
if(x == -2) {
this->_y -= movement;
} else if(x >= INT_MAX / 2) {
this->the_map->change_map(INT_MAX - x);
}
this->state = this->state == UP_ONE ? UP_TWO : UP_ONE;
break;
case 2:
x = this->the_map->collision_check_top(this->_x, this->_y-movement+SPRITE_HEIGHT-5);
if(x == -2) {
this->_y += movement;
} else if(x >= INT_MAX / 2) {
this->the_map->change_map(INT_MAX - x);
}
this->state = this->state == DOWN_ONE ? DOWN_TWO : DOWN_ONE;
break;
case 3:
x = this->the_map->collision_check_right(this->_x-movement+SPRITE_WIDTH-5, this->_y);
if(x == -2) {
this->_x -= movement;
} else if(x >= INT_MAX / 2) {
this->the_map->change_map(INT_MAX - x);
}
this->state = this->state == LEFT_ONE ? LEFT_TWO : LEFT_ONE;
break;
case 4:
x = this->the_map->collision_check_left(this->_x-movement+SPRITE_WIDTH-5, this->_y);
if(x == -2) {
this->_x += movement;
} else if(x >= INT_MAX / 2) {
this->the_map->change_map(INT_MAX - x);
}
this->state = this->state == RIGHT_ONE ? RIGHT_TWO : RIGHT_ONE;
break;

default: break;
}

ostringstream q;
q << "UPDATE users ";
q << "SET screen_id = " << this->the_map->get_id() << ", ";
q << "x = " << this->_x << ", y = " << this->_y << ", state = " << this->state;
q << " WHERE username = '" << this->username << "' LIMIT 1";
mysql_query(this->_mysql, q.str().c_str());

return true;
}


And lastly, I give you main, which is a nice example on how to use it -- this bit's not so nasty! biggrin.gif
cpp
#include "game.h"
#include "functions.h"

int do_mysql(void* foo);

// must be global for the sake of accessing in the thread
game* the_game;
SDL_Surface* players;

int main(int argc, char *argv[]) {
players = SDL_CreateRGBSurface(SDL_SWSURFACE, SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_DEPTH, RMASK, GMASK, BMASK, AMASK);

the_game = new game(players);

map* m1 = new map(1, the_game->get_screen());
m1->set_player_location(180,220);
m1->set_map(IMG_Load(".\\img\\map.png"));
m1->add_object(new object(the_game->get_screen(), ".\\img\\house.jpg", 272, 137, 96, 64));

map* m2 = new map(2, the_game->get_screen());
m2->set_map(IMG_Load(".\\img\\map2.png"));
m2->set_player_location(300,290);
m2->add_object(new object(the_game->get_screen(), ".\\img\\bed.png", 160, 180, 42, 72, &dont_sleep, &do_sleep));
m2->add_exit(new exit((SDL_Surface*)NULL, 300, 300, 25, 32, m1));

m2->add_collidable(0, 0, 120, SCREEN_HEIGHT);
m2->add_collidable(0, 0, SCREEN_WIDTH, 120);
m2->add_collidable(0, 302, SCREEN_WIDTH, SCREEN_HEIGHT-305);
m2->add_collidable(SCREEN_WIDTH-120, 0, 120, SCREEN_HEIGHT);

m1->add_exit(new exit((SDL_Surface*)NULL, 306, 177, 25, 25, m2));

map* main = new map(m1);

the_game->add_map(main);
the_game->add_map(m1);
the_game->add_map(m2);

the_game->do_intro();
SDL_CreateThread(&do_mysql, NULL);

the_game->do_main();

return EXIT_SUCCESS;
}

I'll even be working on a code generator for that, along with a map editor - I plan to develop something similar to RPG Maker when the engine is more complete. Also, a lot of that can be made redundant: in the end, I'll be keeping those methods, but also developing a way to load maps, etc, straight from a database, storing much more stuff in the cloud - easier to update your games, smaller downloads for users, etc. smile.gif smile.gif smile.gif

 | Category: MMORPG Engine
entry 10 Jun, 2009 - 10:12 AM
smile.gif

So, some of you might've tested out that demo, huh? Notice anything lacking? Well, it's supposed to work online and show other players walking around, which it didn't in that release. It worked before I uploaded, then just stopped all of a sudden. Drove me insane, it did. dry.gif

Anyway, a quick tip for all of you. Don't mess with your database structures! blush.gif Especially when you don't reference fields by names. Using the C MySQL API, you don't use row names, you just use a number. Example, a database structure such as this:
CODE
id   |   username

when put onto a MYSQL_ROW struct isn't as simple as named identifiers. Instead, consider this example: (row is our MYSQL_ROW)
CODE
row[0] // the id field
row[1] // the username field

When you go adding fields in between those... things fuck up. smile.gif

 | Category: General
entry 7 Jun, 2009 - 08:15 AM
Well, finally got around to fixing my engine up for a release. It's a little buggy, but it shouldn't crash. Got it all up on sourceforge now: http://sourceforge.net/projects/simplemmorpg and you can download it here.

Anyway, figured I'd have a quick rant about the complexity of sourceforge. It's a nightmare!

But thankfully, you've got me, your trusty gabehabe, to fill you in on how to do it.

I did this through FileZilla but it's pretty standard on how to upload.

See, when you're adding/editing a release, you can't just upload the file from the edit page. Oh, no. Nothing is simple, believe you me. wink2.gif

So...

Connecting!

Connect to the server sftp://frs.sourceforge.net
username/password are your sf credentials. (Come to think of it, I have no idea what you'd do if you registered with an OpenID.)
Port: 22 (default SFTP port)

Then, and here's the bit I had trouble with:

FINDING WHERE TO PUT THAT BLOODY FILE

So, you're now on the server. The path you need to go to should look something like this:
/incoming/u/us/username/uploads
Where you replace username with your own username. For example, if your username is johnsmith:
/incoming/j/jo/johnsmith/uploads
etc...

Then, simply drop the file you want to upload into that directory, go to the add/edit releases in your web browser, and you should see it there.

smile.gif

 | Category: MMORPG Engine
entry 16 May, 2009 - 08:04 AM
So, I finally got around to putting the server communication stuff in a different thread. smile.gif

Main also got a little longer! And I've made my game wrapper slightly more detailed, so now you can add maps from main (I was still adding them direct from within the class while I was testing it)

{side note: FUCK, got a memory leak} sad.gif
Probably related to the MySQL in some way, it will be sorted.
<edit>heh, got it. My bad, I forgot to call SDL_FreeSurface somewhere.</edit>

So, while I sort that out, why not check out the usage of the engine?

It's slightly longer, mostly due to the map creation in there, and there's a few new lines thrown in, such as creating the thread.

main.cpp
#include "game.h"

int do_mysql(void* foo);

// must be global for the sake of accessing in the thread
game* the_game;
SDL_Surface* players;

int main(int argc, char *argv[]) {
players = SDL_CreateRGBSurface(SDL_SWSURFACE, SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_DEPTH, RMASK, GMASK, BMASK, AMASK);

the_game = new game(players);

map* m1 = new map(1, the_game->get_screen());
m1->set_player_location(180,220);
m1->set_map(IMG_Load(".\\img\\map.png"));
m1->add_object(new object(the_game->get_screen(), ".\\img\\tile1.png", 30, 30, 25, 25));
m1->add_object(new object(the_game->get_screen(), ".\\img\\tile1.png", 10, 250, 25, 5));
m1->add_object(new object(the_game->get_screen(), ".\\img\\tile2.png", 180, 150, 25, 25, NOTHING, &found_potion));

map* m2 = new map(2,the_game->get_screen());
m2->set_map(IMG_Load(".\\img\\map2.png"));
m2->set_player_location(145,227);
m2->add_exit(new exit(".\\img\\tile3.png", 120, 240, 25, 25, m1));
m1->add_exit(new exit(".\\img\\tile3.png", 180, 210, 25, 25, m2));


the_game->add_map(m1);
the_game->add_map(m2);

the_game->do_intro();
SDL_CreateThread(&do_mysql, NULL);

the_game->do_main();

return EXIT_SUCCESS;
}

 | Category: MMORPG Engine
entry 14 May, 2009 - 10:59 AM
Well, I wanted to make something that anyone can make a game with.

I think I've done it.

The engine still isn't complete, but I've tidied up the main code a little.

Perhaps a little too much.

main.cpp
#include "game.h"

int main(int argc, char *argv[]) {
game *_game = new game();
_game->do_intro();
_game->do_main();

return EXIT_SUCCESS;
}


This doesn't account for the "data entry" type bits of creating a game using the engine, ie, creating a map.

Though that's still pretty simple.

create a map
    map* m1 = new map(1, this->_screen);
m1->set_player_location(180,220);
m1->set_map(IMG_Load(".\\img\\map.png"));
m1->add_object(new object(this->_screen, ".\\img\\tile1.png", 30, 30, 25, 25));
m1->add_object(new object(this->_screen, ".\\img\\tile1.png", 10, 250, 25, 5));
m1->add_object(new object(this->_screen, ".\\img\\tile2.png", 180, 150, 25, 25, NOTHING, &found_potion));

 | Category: General
entry 14 May, 2009 - 01:25 AM
http://www.google.co.uk/search?q=online+rpg+engine

Rank 8 of 350,000 results. </dream.in.code> strikes again with it's awesome page rank!

That is all.

 | Category: MMORPG Engine
entry 13 May, 2009 - 10:15 AM
Yup, multiplayer. smile.gif

It's actually quite simple. It's slow for the time being, I've got too much going on in a single loop (it will all be multithreaded in the end) but it's certainly on its way to being a decent (small) online multiplayer rpg engine. (I refuse to say that thing that all 12 year olds want to make)

The concept is simple. When the player moves, their location will be updated on a database. (located on a web server) Periodically, these coordinates are downloaded for all users on the same screen, and they are drawn on. (This is what makes it slow for the time being)

The plan is to process all that information in another thread. Meaning, it won't have any effect on the main game loop, and thus, it won't slow down gameplay as a whole.

To express the simplicity of it (it will obviously become more complex over time) this is how they are downloaded (this is a simple MySQL SELECT statement)

SELECT * FROM users WHERE screen_id = 1 AND user_id != 1

Obviously this isn't hard coded, and the screen & user id are actually called in from the game details. Something like:

cpp
ostringstream q;
q << "SELECT * FROM users WHERE screen_id = " << the_map->get_screen_id() << " AND user_id != " << p->get_userid();


I have a demo ready, and I've actually walked around on a map with several other people at the same time, so I know it works. I won't be releasing it to you DIC heads just yet though, there's quite a lot of work to get it done until it's actually good enough to show off completely. (Though I've tested it with a few of my followers on twitter)

Oh, and one more thing...
In a slightly unrelated note, I'm gonna throw a quick tip out there for you MySQL Connector/C users out there. This is an issue I experienced with my code, and it relates to a memory leak. Something that seemed to be missed out in a lot of the examples.

DON'T FORGET TO FREE THAT MYSQL RESULT!

In other words: mysql_free_result(result);!!!

I went from 5mb to 18mb in memory because I didn't do just that. And I spent at least an hour hunting it down.

 | Category: MMORPG Engine
entry 22 Mar, 2009 - 09:07 AM
So I've finally decided to work on a pretty big project. Doing it all by myself, the best way to do it IMO.

This new project is a 2D game engine. It'll be sooooo easy to use, and it'll be for creating games with a similar gameplay to the early Final Fantasy games. Nothing flashy, but fun all the same.

It could also expand into a game maker, something like RPG Maker if I ever get around to it. I have a habit of getting distracted from my side projects.

So, this engine. It's written in C++ using SDL for graphics. I've been working on it for a total of about 10 hours (maybe more, maybe less... I haven't been keeping track)

So far, there's sprite animation, and the player can walk around on a map. Objects can be loaded, and the player will collide with them when they try to walk into them. You can also load NPCs and talk to them. (Old FF style dialog boxes)

The map is loaded from an image, and images (objects) can be loaded onto that. I just finished figuring out some nasty looking function callbacks to "add an action" to an object, ie, when the player inspects the object, they could find an item, it could say something, could trigger an event. These events are in user-defined functions, and a pointer to these functions is passed to the object.

For those of you interested, here is your typical "gabehabe's test thingy" before it gets added to the project:

cpp
#include <iostream>
//#include<sdl/sdl.h>

using namespace std;

void a() {cout << "a";}
int b() {return 2;}

// experimentation
// template<class T>T exec(T(*f)()){return f();}

template <class T>
class object {
public:
void set_special_action(T(*f)());
T perform_special_action();
private:
void* action;
//SDL_Surface* img;
//SDL_Rect offset;
//int times_to_perform;
};

template <class T>
void object<T>::set_special_action(T(*f)()) {
this->action = (void*)f;
}

template <class T>
T object<T>::perform_special_action() {
return ((T(*)())this->action)();
}


int main(int argc, char* argv[]) {
object<int> p;
p.set_special_action(&b); // add b() as the action
cout << p.perform_special_action(); // outputs b() (which is 2)
cin.get();
return 0;
}


More news as this engine develops, but it's looking to be quite an ongoing project.

Future developments include exits to move from one screen to another (obviously a necessity), ability to add "second level" objects, that the player can walk behind (creates a slightly more 3D interaction) and weather. (Stuff like snow, with the ability to settle on surrounding objects)

Any special feature suggestions are greatly appreciated~! biggrin.gif

 | Category: Web Development
entry 28 Jan, 2009 - 11:34 AM
Only a short entry. This is something that can be a bitch to figure out, and pretty difficult to find the simplest solution. So here I am, providing you with said solution out of the generosity of my heart! smile.gif

So, you may have heard of a file called .htaccess which is part of a configuration for Apache. We'll be using this, plus a one-line PHP page to redirect to the correct file each time. yay!

The problem
We have a Linux server. Linux filenames are case sensitive, and URIs are no different. This can pose a problem, correct?

The solution
This is soooo simple, yet not easy to find. The simplest way would be to redirect any URL which contains uppercase letters to this PHP script, right? (explained later)
So, essentially we will need this:
.htaccess
#enable rewrite engine
RewriteEngine On

#if our URI contains an upper case letter [A-Z]
RewriteCond %{REQUEST_URI} [A-Z]
#rewrite it to our PHP page, passing the given URI as a GET variable
RewriteRule ^(.*)$ http://www.example.com/redirect.php?uri=%{REQUEST_URI} [L,R=301]

So there we have it! Or not. You might've been an eager beaver and tested it already, before reading on. If you did, you will have noticed that all your images are b0rkT. OH NOEZ! *slaps forehead*

So how can we fix that?!
Simple, actually. We can add another rewrite condition, this one only rewriting any pages which have .php in their extension. And obviously, you could customise it to suit other pages extension, whichever you please! yay!

So, the final htaccess file will look something like this:
.htaccess
RewriteEngine On

RewriteCond %{REQUEST_URI} [A-Z]
RewriteCond %{REQUEST_URI} ^(.+)\.php$
RewriteRule ^(.*)$ http://www.example.com/redirect.php?uri=%{REQUEST_URI} [L,R=301]


-----------------------------------
Thanks to Mocker:
If you really wanted, you could also check if the file exists: if it doesn't then we try lowercase. If it does, we go straight to it:
RewriteCond %{REQUEST_URI} !-f
-----------------------------------

Now, the PHP script is even simpler. We can have it as one line:
PHP
<?php (isset($_GET["uri"])) header("Location: " . strtolower($_GET["uri"])); ?>


Or we could expand on it a little, so that if the user browses to the page without being redirected (ie, if $_GET["uri"] isn't set) we can redirect them to our home page:
PHP
<?php 
if(isset($_GET["uri"])) header("Location: " . strtolower($_GET["uri"]));
else header("Location: ./"); // the index file of this folder. alternatively: header("Location: http://www.example.com");
?>


The drawbacks
Forgot to mention this! Thanks to Mocker for the reminder. You'll have to use name your pages in lowercase in order for this to work, since it we use strtolower()
It may not be the most elegant approach, but it certainly works. It's short and simple, much like my thoughts. smile.gif

Also, it currently only works with URIs that end with .php
The reason for this is that if we start manipulating the case of some of the GET data which comes after the actual filename, we could corrupt the page. It could be modified to only convert everything before the first index of "?" to lowercase, leaving everything after there, but I'm not sure how this would affect the speed of the method. Have a play with it!

So, a very brief blog entry, which will hopefully get you up and running with case insensitive URIs on your Linux box! If you have any questions, feel free to ask: I feel I haven't been as clear today as usual, for which I apologise. smile.gif

Happy coding!

 | Category: General
entry 20 Dec, 2008 - 11:12 AM
Wow. Well over a month since my last entry, and now it's nearly Christmas!

OK, so this is gonna be a little bit of an off-topic entry. But I wanna let you guys know that I'm gonna get back to programming in my free time!
[That's right guys, gabehabe stopped programming for fun since he started work]

So yeah, about my new job. I work as a software developer, I make database applications. The main language I use is FoxPro, but since I started I've used a buncha stuff. Mostly because my boss was real set on extracting data from some ridiculously old database for the client. So I had to set up a text printer, and a printer hook. Run the old system in a DOS emulator [yeah, it's that old] and write a script to send keypresses to the application, to print each record. A total of ~8000 records.
So, after that, I had to write some parsers, too. All together, I used a bunch of languages to do it all, depending on my mood.
I worked with: FoxPro, C++, C#.NET and AutoIt. [yuck]

I recently got the T-Mobile G1, which runs Android~ Google's new mobile operating system. And I gotta say, it's nice.

It's a part of the Open Handset Alliance, which is basically a way of making it nice for developers to, well, develop for it.

Apart from the fact that the documentation for Android royally sucks. It's so hard to just make it all fit together!

I've got a few ideas, so I'll be back to coding for fun soon.

By the way, it's all done in Java! [Locke37 will be pleased]

Short entry, but I'm basically just letting you guys know that I'll be back to the regular blogging as of the beginning of 2009. Which is less than 2 weeks away~! Oh my.

 | Category: Interpreters
entry 4 Nov, 2008 - 11:03 AM
I've decided that I'm going to develop my own language. For now, it will be interpreted, but as I get more into compiler theory, I'm hoping to be able to build a compiler for it.

It's going to be as close to English as possible. And the way that I'll do this is not to parse every single word, but to only parse certain ones.

Example, the programmer could type something like this:
print "This language is going to rock my socks" on the console

which would simply be interpreted as this:
print "This language is going to rock my socks"

Note that the programmer could also write it exactly as it will be interpreted. Basically, they can just go for whatever makes sense to them.

It's basically going to be aimed at people who have never written code before. I know it's going to be difficult to get it so close to English, but those of you who know me know that I'm always game for a challenge.

Let's look at a better example. To read a file into a string variable, then output the string, the programmer could do this:
CODE
create str as type: string
read file "C:\\file.txt" to str
print str on the console


The code would be executed at runtime, like my BF interpreter, so the user wouldn't have to see any C++ in an output file, or anything like that. Since it'll be done at runtime, the variables that the user creates will most likely be stored in some kind of memory array, since we can't name variables at runtime.

The code that would then be executed (in C++ since I'll be doing this in C++) would be something along the lines of:
cpp
// create str as type: string
string str; // actually stored in some kind of array of data, since we can't name variables at runtime
// read file "C:\\file.txt" to str
ifstream file;
file.open("C:\\file.txt");
if (file.is_open()) {
while (!file.eof()) file >> str;
file.close();
} else { // automatically generate an error message
cout << "Error: File could not be located";
}
// print str on the console
cout << str;


If anyone has any suggestions, please let me know. smile.gif

Thanks for reading!

 | Category: Interpreters
entry 3 Nov, 2008 - 12:59 PM
I love a bit of brainfuck. I've been working on this interpreter for about a total of an hour, and it's already finished. It's fully functional, and interprets any brainfuck application.

The best part is, it's only 61 lines long! Interpreting the brainfuck code itself takes only 12 lines~ But I've added some more functionality to my application so that it can be called from the command line, and interpret at runtime. No translated code, no output files~ It simply executes the BF code.

I've added two commands to it:
BF-i -? will display a little bit about the program~ Who it was written by, which language it was written in, etc etc~

BF-i -i C:\file.bf will interpret the file located at C:\file.bf

Simple to use! biggrin.gif

It's available to download here, including the MS executable, C++ source code, and a small about file.

I'll write up a tutorial on creating an interpreter soon. smile.gif

Lastly, here is the code:
BF-i
/*
* A brainfuck interpreter
* Author: Danny Battison
* Contact: gabehabe@gmail.com
*/

#include <iostream>
#include <fstream>
using namespace std;

void DisplayHelp();

int main(int argc, char *argv[]) {
if (argc < 2 || argc > 3) {
DisplayHelp();
return EXIT_FAILURE;
}
if (!strcmp(argv[1], "-?")) {
cout << "BRAINFUCK INTERPRETER: WRITTEN BY DANNY BATTISON" << endl
<< "This program is designed to interpret a brainfuck application." << endl
<< "Written in C++" << endl
<< "Contact the author: gabehabe (at) gmail (dot) com";
}

else if (!strcmp(argv[1],"-i")) {
if (argc < 2 || argc > 3) {
DisplayHelp();
return EXIT_FAILURE;
} else {
ifstream file;
file.open(argv[2]);
if (!file.is_open()) {
cout << "ERROR: File could not be found.";
return EXIT_FAILURE;
}
string bf = "";
char buffer;
file.get(buffer);
bf += buffer;
while (!file.eof()) {file.get(buffer); bf += buffer;}
file.close();
char* ptr = new char[5000];
int sub;
for (sub = 0; sub < 5000; sub++) ptr[sub] = 0;
sub = 0;

unsigned int i;
int loopPosition = -1;
for (i = 0; i < bf.length(); i++) {
switch (bf[i]) {
case '+': ptr[sub]++; break;
case '-': ptr[sub]--; break;
case '>': sub++; break;
case '<': sub--; break;
case '.': cout << ptr[sub]; break;
case ',': ptr[sub] = getchar(); if (ptr[sub] == 13) {ptr[sub] = '\0'; loopPosition = -1;} break;
case '[': loopPosition = i; break;
case ']': if (loopPosition != -1) {if (ptr[sub] != '\0') i = loopPosition-1; else loopPosition = -1;} break;
}
}
}
return EXIT_SUCCESS;
}
}

void DisplayHelp() {
cout << "Invalid arguments. Example Usages:" << endl
<< "\tInterpret:\tbf.exe -i C:\\file.bf" << endl
<< "\tAbout:\t\tbf.exe -?";
}

 | Category: Key Concepts and Theory
entry 2 Nov, 2008 - 01:45 PM
Topic Requested By: red_4900

This article is going to cover three methods of programming: Object Oriented, Aspect Oriented, and Procedural. Of course, these styles have their benefits and their liabilities. But solutions often combine all these styles, in order to create the most managed code.

To those of you who know me: You know that I'm not much of a writer. I keep it on more of a "layman's terms" basis, keeping it short and to the point. This is why I'll be offering a demonstration, using the widely known "fizz buzz" example: Print numbers 1 to 100, printing "fizz" if the number is a multiple of 3, "buzz" if it is a multiple of 5, and "fizz buzz" if it is divisible by both 3 and 5.
NOTE: The solution offered will be a little impractical. I need to break it down into more functions than necessary, to demonstrate the various styles. At the end of this entry, I'll provide a final solution, which is the simplest possible.

So what are they, put simply?

Object Oriented Programming: A style of programming which is based around objects. This is the most common style of programming in the industry.

Aspect Oriented Programming: Often written to complement an OOP solution. Hard to explain in short, but basically, it's main use is to keep your OOP code organised, without having to scatter various aspects of code across several objects.

Procedural Programming: This is the "old school" style of programming. Less commonly used now~ The main language (which is still used within the industry) which still focuses on this style is C.


These sound interesting. How do I know which is best for me?
Like I already said, solutions often combine these styles. The whole purpose is to create code that is well managed. Time to get into the more nitty-gritty stuff~


Procedural Programming
Like I said, this is much less common than object oriented programming nowadays. However, this doesn't mean that procedural programming is without benefits! In fact, the main reason that I like C++ is that it allows the programmer to combine procedural programming with OOP. procedural programming is also known as "Functional Programming."

Basically, procedural programming is entirely a 1-way system. There's no major data grouping (the main benefit of OOP) so you're basically working with nothing more than variables, loops, and functions. (Everything but objects, basically)

The obvious benefit to procedural programming is that you don't need objects for everything. Take a look at Java, as an example. Everything has to be contained within a class. What about if you just want one function to do something really simple? (Obviously, this is also a drawback of OOP, so you'll be reading this again in a bit)

The main drawback is that there is no major data grouping. With an object oriented language, it's easy to keep everything organised~ Variables and methods go in the appropriate classes.

Here's the previously mentioned example. Remember, this is not the best way to tackle this problem. It's been broken down into various functions to create a better demonstration.

The key point to notice here is that our variable has to be passed around to various functions. OK, so this could be solved by a global variable, but no one likes global variables... tongue.gif

Procedural Demonstration
#include <stdio.h>

// no objects here!

void FizzBuzz(); // our function to perform the fizz buzz operation
bool ByThree(int); // a function to check if a number is divisible by 3
bool ByFive(int); // a function to check if a number is divisible by 5
void PrintFizz(); // a function to print the word "Fizz"
void PrintBuzz(); // a function to print the word "Buzz"

int main() {
FizzBuzz();
return 0;
}

void FizzBuzz() {
int i = 1;
for (i; i <= 100; i++) {
if (ByThree(i)) PrintFizz();
if (ByFive(i)) PrintBuzz();
if (!ByThree(i) && !ByFive(i))
printf("%d", i);

printf("\n");
}
}

bool ByThree(int x) {return (x % 3 == 0 ? true : false);}
bool ByFive(int x) {return (x % 5 == 0 ? true : false);}
void PrintFizz() {printf("fizz");}
void PrintBuzz() {printf("buzz");}


For more information: http://en.wikipedia.org/wiki/Procedural_programming

Object Oriented Programming
OOP is a great way to manage your data. Put simply, it's a way to store variables, and methods together, to create an object. When creating your objects, you'll have to take into account how this object is going to need to interact with various other objects. This could be considered a disadvantage, since it takes more planning. Also, it can sometimes be awkward to come up with the best way for your object to interact with another.

Remember the key benefit of procedural programming? Well it's time for a reminder.
When programming in a language which is purely based around OO concepts (such as Java) then you might run into a bit of an annoying problem. What if you have a method to do something, which doesn't specifically belong in any of your classes? Maybe it can be applied to more than one of your classes~ Why rewrite it in each class? However, there are solutions to this. One way would be to use a "general" class, and call the methods from this class each time. Another way is to create a base class, containing these general methods. Then, each of your objects which require the method will inherit it from the base class.

Time for that example again. The key thing to notice now is that we no longer need to pass that variable around everywhere. It simply gets accessed from within the object.
Object Oriented Demonstration
#include <cstdio>

class FizzBuzz {
public: // our publicly accessable stuff
void Execute(); // our function to perform the fizz buzz operation
public: // our private stuff, that only the class really needs
int i; // the variable which we will use in our loop
bool ByThree(); // a function to check if a number is divisible by 3
bool ByFive(); // a function to check if a number is divisible by 5
void PrintFizz(); // a function to print the word "Fizz"
void PrintBuzz(); // a function to print the word "Buzz"
};

void FizzBuzz::Execute() {
this->i = 1;
for (i; i <= 100; i++) {
if (this->ByThree()) this->PrintFizz();
if (this->ByFive()) this->PrintBuzz();
if (!this->ByThree() && !this->ByFive())
printf("%d", i);

printf("\n");
}
}

bool FizzBuzz::ByThree() {return (this->i % 3 == 0 ? true : false);}
bool FizzBuzz::ByFive() {return (this->i % 5 == 0 ? true : false);}
void FizzBuzz::PrintFizz() {printf("fizz");}
void FizzBuzz::PrintBuzz() {printf("buzz");}

int main() {
FizzBuzz *fb;
fb->Execute();
return 0;
}


For more information: http://en.wikipedia.org/wiki/Object_oriented_programming

Aspect Oriented Programming
Basically, AOP is used to separate your solution into various aspects. It best complements OOP concepts, as previously stated.

AOP is used to allow an application to grow as time progresses. It allows a programmer to modify a static object-oriented solution to create a system which is capable of growing and meeting new requirements.

Consider AOP to be a way to meet requirements which are later added to a specification. You will develop an object-oriented solution for a client, and a few years later, your client comes back to you, asking you to alter the application to meet some new requirements. Rather than going through all the old code, you will dynamically change the application.

No demonstrations here. The best way to explain is with an example of something other than code. ohmy.gif

The best way to explain AOP is to compare it to an object in the real world. Consider a packet of crisps. (That's potato chips, if you're in America wink2.gif)
The manufacturers are always reducing the salt content, and making them taste better, right? Do you think they start from scratch when they make these changes?
More likely, they would make alterations, instead of completely re-inventing the flavour.

For more information: http://en.wikipedia.org/wiki/Aspect_oriented_programming




And after all that, we're finally done! Thanks for reading! smile.gif

 | Category: Software
entry 31 Oct, 2008 - 04:46 PM
This is a topic which was inspired by this thread. Not a lengthy blog entry, but definitely worth a read, if you're looking for an alternative to Visual Studio.

First off, the application is available here.
(http://www.icsharpcode.net/OpenSource/SD/)

I would have used Visual Studio more, but it doesn't agree with the laptop. I have no idea why. So from the point I decided to learn about .NET, I had to find an alternative IDE. Honestly, I'm glad VS wouldn't agree with the laptop. #Develop is a brilliant application. And the best thing is, it's open source, so you can alter it to suit you more personally, or just check out how it works!

Anyway, that's how I came to use #Develop.

It's hard for me to compare it to Visual Studio, since I've only actually used VS once or twice. But I'll do my best.

The IDE is actually very similar to Visual Studio, in that you get your design view, code view, syntax highlighting, etc. Though, as you'd expect, these are the norm for pretty much any IDE, including the one that I (plan) to develop.

So why choose #Develop?

It's a comfortable IDE. It's just as flexible as Visual Studio, with the ability to "pin" various components to remain in view, including a clipboard recorder, ASCII tools, quick-click license rules (such as the ability to simply click a menu item and the entire license will appear in your code as a comment)

Like Visual Studio, it comes with the ability to create an installer, using a wizard. It has a subversion tool (SVN) and various other add-ins.

You can entirely configure your project, including debug/release target files, create your own compile setting, etc.

Lastly, it comes with a resource manager, for dealing with those all-important resx files.

Compatible languages~ Which languages can I develop in with #Develop?
Quite a few, actually. More than I'd even heard of, before I downloaded it.
1) Boo
2) C#
3) F#
4) ILAsm
5) Python
6) VB.NET

3 Pages V  1 2 3 >  
0 user(s) viewing
0 guest(s)
0 member(s)
0 anonymous member(s)

gabehabe's off-topic ramblings
Follow me on Twitter!
lol, my other blog died a horrible lonely death. Ah well.

Smiley of the [however often I change it]
IPB Image

Contact Me
e-mail: gabehabe@gmail.com

Google Talk: gabehabe@gmail.com
MSN: gabehabe@hotmail.com
Yahoo: gabehabe (rarely used)
AIM: gabehabe (rarely used)

Skype: gabehabe

Want me to work for you? [click]

My Blog Links