Pages

Monday, October 24, 2011

New Downloads / Windows Binaries

Hello!

New downloads!

<One year ago I started this project with many objectives, one of them was to make it multi-platform so yesterday I decided to compile my projects under Windows, or at least try to do it...>

<And here it comes the ingredients for my Windows recipe:
  1. A virtual machine emulator (a.k.a. Virtualbox ), Somebody will prefer a dual-boot configuration or just Windows, well, it's up to you...
  2. A Windows installation disk, you have one, right? (Important: First, clean the dust)
  3. Code::Blocks 11.05 compiler + minGW (Install, Next > Next > Next > Next > Finish.... Windows is SO user-friendly...)
  4. An assorted mix of libSDL libraries (SDL, SDL_image,SDL_ttf,SDL_net): Download, extract, and then mix them so you put all \include and all \lib files together, and of course the DLLs too.
  5. Download the sources too..
  6. If you want to compile them you will have to set up the compiler so it uses the sdl\include and sdl\lib paths, other way, it will simple refuse to work.
Another important thing is that you have to change all the includes:

#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "SDL/SDL_ttf.h"
#include "SDL/SDL_net.h"
#include "SDL/SDL_thread.h"  

In all the source files with:


#include "SDL.h"
#include "SDL_image.h"
#include "SDL_ttf.h"
#include "SDL_net.h"
#include "SDL_thread.h"  

(paths are a little bit different under Windows..)

<And well, that's it! after doing that I got the life game and the three rpg sub-projects working >

<I wanted to include the chat server / client project too, hey ! I really wanted to do, but I found an unexpected and silly problem, the chat server uses the std input / output for everything, I cout << what the clients "say" and get cin >> the clients input, it works fine under Linux, but under Windows, it redirects the output and errors too to the files "stdout.txt/stderr.txt", it is the normal behavior, if you are making a graphical project, you don't have the console, right? but what if you need it?>

<I have been goggling for solution and finally I found something that should work: > 


SDL_Init(SDL_INIT_VIDEO);    
if (ctt)    
{        
freopen("CON", "w", stdout);        
freopen("con", "w", stderr);        
fclose( ctt );     
}

<That was supposed to set the output again to console, I added the code, and when I executed the project under code::blocks, It magically worked again, so I happily rebuild the project...>

<And then I executed the resulting .exe, it opened a console window... (have I said it was black? completely black?) :(, that's when I decided I wont compile it for Windows ( at the moment), if anybody had found that problem and feels eager to help, I will really appreciate it...>

<In the next post, the chat server /client...>


See you
JB

Thursday, October 13, 2011

SDL_net / SDL_threads(1): The Threading beast, is it so dangerous?

A multi-threaded echo server....

<What is the most important thing beyond every mmorpg? is it the history?, maybe the fancy 3d graphics? nope... it is the network play!>

<When I started the project , one year ago my objective was to bring the game on-line, I just didn't thought how many new things I needed to learn, the C++ language , the libSDL  library, all the other extension libraries (SDL_image, SDL_ttf, SDL_net, SDL_thread, ...), how to use blogger... , the Gimp, etc, etc....>

<It has been a long trip, but now I have arrived where I wanted to be, to the network>

<On the top of the page there is an screen-shot showing my first networking demo, a multi-threaded socket server using SDL_net and SDL_thread>

<I start the server and then I can connect with telnet to the server, every thing I type on the telnet window goes to the server and it returns the message to the sender, maybe you can think it is something too easy, but let me show why it's important...>

<Here what you can't see is more important than what you see, that's the project structure:>


<I encapsulate all the network code into two classes: csockserver and csockclient, fist one opens an SDL_net server socket who is going to sit and wait for incoming connections, when it happens (new client connection), it creates a new csockclient and adds it to the vector, then the csockclient starts a thread and the thread wait for data incoming to the server for a client, when it happens it just echoes the data back to the client>

<it is a very simple way to handle data, a perfect base to start adding new features, now if we change just a few lines we will have a chat server, but threaded>

<I have remarked the thread thing because when I started to look for demos / tutorials to use SDL_net I basically found nothing related to using it with threads, the question is a server needs threads, we can't stop the server logic just to see if a client is sending data, and for the server I'm going to use more threads: (for example , for the A.I.) so many things can happen at the same time, making threaded code is very hard, because any small mistake is going to crash the server, make your computer leak memory, or even worse open a security hole....>

<I'm going to finish the next step (the chat server) and I will post the c++ code>

<Ideas / suggestions are always welcome>

<see you, in the chat>

JB

<B.T.W. Ogres are ugly, SDL_net + threads too, what could happen if you mix them?? ;)>

Sunday, October 2, 2011

Code::Blocks(17) RPG 4 - Rpg Demo working, Player creation end.

A preview before starting the networked part:



I have made so many changes in the code that it's gonna take very long to post all them, so what I'm going to to is to make a list with updated things:

<Engine class:>
  • I have added 3 fonts to the game, they only change in size so they can used for main tittles or the plain text in the game.
  • TextOut function to draw text.
  • IntOut function to draw numbers
  • FillRect to fill a rectangle with a color
  • Window function to switch between windowed / full screen mode
<Player class:>
  • Accel, Speed, Angle variables added
  • Now the player's point of view is defined by an angle, an the movement is based in that angle, when you press <forward> player speed will increase by it's accel value (to a limit) and move accordingly to that.
<Timer class:>
  • Needed two timers in the game so I found the easiest way to use them was to encapsulate into a class, now I have a timer for FPS calculation and another to regulate framerate.
<Text Input class:>

  • A new class used to grab input from keyboard and add to a string (Used to write player's name)
 <Game class:>
  • DrawMap: In that function I have made a small but very important optimization: it drawed all the tiles in the three layers in the map but that was a mistake because not all the three layers were filled, only the first one, so what I did was to check in 2nd an 3rd layer if the tile was empty and then if it isn't, draw it, a simple change that made the processor use change from 99% to 30%, not too bad!
  • ShowStats: a function to draw player stats (name, attibutes, skilss..)
  • DrawGUI:To draw player's life and magic points
  • DrawDir: To draw a single dot in player's point of view
<The textout and intout function had a nasty mistake that was leaking memory very fast, it was a bug hard to find but now it's corrected, the game only uses 3.4MB ram in my ubuntu 32bits computer.>