Witam po długiej nieobecności, jeśli to kogoś interesuje, bla, bla...

Szykuję się do pisania jakiejś gierki 2D pokroju Tibii (dla wciąż początkującego, dobre i to). Ściągnąłem biblioteki SDL, SDL_ttf oraz SDL_net. Od razu dodam, że kilka próbnych gier w SDL-u już zrobiłem (strzelanki).

Do rzeczy: problem zaczyna się w jednym z aspektów komunikacji serwer - klient, a konkretnie w procedurze:

//#include, #include, #include...

//...

using namespace std;

const int MAX_USER_CON=32;

class connections //użytkownicy
    {
        public:
        string name; //nick
        UDPsocket user_socket; //gniazdo UDP
        UDPpacket *user_packet; //pakiet osobisty
        bool estabilished; //czy ten slot użytkownika jest zajęty? 
    };

connections Users[MAX_USER_CON];

//...

void newconnectionattempt(string name, SDLNet_SocketSet set) 
       //służy do dodania nowego użytkownika do chatu
    {
        int channel_x=-1;
        for (int i=0; i<MAX_USER_CON; i++)
            {
                if ((channel_x==-1) and (!Users[i].estabilished)) 
                       //kanały chatu w grze, szuka pierwszego wolnego
                    {
                        channel_x=i;
                        int bcheck;
                        bcheck=SDLNet_UDP_AddSocket(set,Users[channel_x].user_socket); 
                                //dodaje nowe gniazdo do seta
                        if (bcheck>-1) //jeśli jest jeszcze wolne miejsce
                            {
                                Users[channel_x].name=name; //nick
                                Users[channel_x].estabilished=true; //jest połączony
                                Users[channel_x].user_packet=SDLNet_AllocPacket(128); //inicjacja pakietu osobistego
                            }
                        break;
                    }
            }
    }

A kompilator wypluwa:

     error: expected primary-expression before ',' token
     error: 'SDL_reinterpret_cast' was not declared in this scope

i wskazuje na linijkę

     bcheck=SDLNet_UDP_AddSocket(set,Users[channel_x].user_socket);

Próbowałem:

  • w Googlach,
  • odwołać się do zmiennej zewnętrznej socset (zamiast set),
  • odwołać się do zmiennej zewnętrznej Asocket (zamiast Users[channel_x].user_socket),
  • grzebać w ustawieniach kompilatora i debuggera (niewiele, nie chciałem nic popsuć).
    No i kilka razy sprawdzałem składnię, ale może ja jakiś ślepy jestem...

Z góry dziękuję za wszelką pomoc.

EDIT:

Cały kod serwera (program w budowie):

 
//SDLUTNET.H
//Chwilowo jest to coś na kształt komunikatora
#ifdef __cplusplus
    #include <cstdlib>
#else
    #include <stdlib.h>
#endif
#ifdef __APPLE__
#include <SDL/SDL.h>
#else
#include <SDL.h>
#endif

#include <fstream>
#include <math.h>
#include <SDL_ttf.h>
#include <iostream>
#include <sstream>

#include "SDL_net.h"

using namespace std;

const int MAX_USER_CON=32;

UDPsocket Asocket;
UDPpacket *Apacket;
SDLNet_SocketSet socset;

string servlog[512];
int curlogpoint=0;

class connections
    {
        public:
        string name;
        UDPsocket user_socket;
        UDPpacket *user_packet;
        bool estabilished;
    };

connections Users[MAX_USER_CON];

void EstabilishUDP()
    {
        SDLNet_Init();
        Asocket=SDLNet_UDP_Open(9999);
        Apacket=SDLNet_AllocPacket(512);
        socset=SDLNet_AllocSocketSet(MAX_USER_CON);
        for (int i=0; i<MAX_USER_CON; i++)
            {
                Users[i].estabilished=false;
            }
    }

void EndUDP()
    {
        SDLNet_UDP_Close(Asocket);
    }

string UDPpacket_str(UDPpacket *packet) //świeże, jeszcze nie testowane
    {
        string s;
        for (int i=0; i<packet->len; i++)
            {
                s[i]=packet->data[i];
            }
        return s;
    }

void newconnectionattempt(string name, SDLNet_SocketSet set)
    {
        int channel_x=-1;
        for (int i=0; i<MAX_USER_CON; i++)
            {
                if ((channel_x==-1) and (!Users[i].estabilished))
                    {
                        channel_x=i;
                        int bcheck=0;
                        bcheck=SDLNet_UDP_AddSocket(set,Users[channel_x].user_socket);
                        if (bcheck>-1)
                            {
                                Users[channel_x].name=name;
                                Users[channel_x].estabilished=true;
                                Users[channel_x].user_packet=SDLNet_AllocPacket(128);
                            }
                        break;
                    }
            }
    }

void server_checkpanel() //sprawdza aktywność użytkowników 
    {
        for (int i=0; i<MAX_USER_CON; i++)
            {
                int selectedactivity=SDLNet_UDP_Recv(Users[i].user_socket,&*Users[i].user_packet);
                if (selectedactivity>0)
                    {
                        int lenpack=Users[i].user_packet->len;
                        for (int j=0; j<lenpack; j++)
                            {
                                servlog[curlogpoint][j]=Users[i].user_packet->data[j];
                            }
                        servlog[curlogpoint]="["+Users[i].name+"]: "+servlog[curlogpoint];
                        curlogpoint=(curlogpoint+1)%512;
                    }
            }
    }

void SDLUTCom_broadcast(string msg) //przyszła procedura - chat ogólny
    {
    }

void SDLUTCom_private(string adresser, string pmsg) //przyszła procedura - chat prywatny
    {
    }
//MAIN.CPP
#ifdef __cplusplus
    #include <cstdlib>
#else
    #include <stdlib.h>
#endif
#ifdef __APPLE__
#include <SDL/SDL.h>
#else
#include <SDL.h>
#endif

#include <stdio.h>
#include <string.h>

#include "SDLUT_BASE.h" 
   //SDLUT_BASE jest za długi, żeby go wrzucać, ale zawiera linijkę #include "SDLUTNET.h"

int main ( int argc, char** argv )
{
    if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
        {
            printf( "Unable to init SDL: %s\n", SDL_GetError() );
            return 1;
        }
    atexit(SDL_Quit);
    SDL_Surface* screen = SDL_SetVideoMode(640, 320, 16, SDL_HWSURFACE|SDL_DOUBLEBUF);
    FontInit("comdata/font.ttf",20); //zawarte w sdlut_base.h, działa na 100%
    EstabilishUDP();
    textcolor(128,128,0); //zawarte w sdlut_base.h, działa na 100%


    bool done = false;

    while (!done)
    {
        SDL_Event event;
        while (SDL_PollEvent(&event))
        {
            switch (event.type)
            {
            case SDL_QUIT:
                done = true;
                break;


            case SDL_KEYDOWN:
                {
                    if (event.key.keysym.sym == SDLK_ESCAPE)
                        {
                            done = true;
                        }
                    else //jeszcze do zrobienia
                        {
                        }
                    break;
                }
            }
        }

        server_checkpanel();

        SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 255, 255, 255)); //czyszczenie ekranu

        for (int i=10; i>0; i--) //log
            {
                int cpoint=curlogpoint+10-i;
                if (cpoint<0) cpoint=cpoint+512;
                if (servlog[cpoint].length()>0)
                    {
                        textwrite(10,i*25+10,servlog[cpoint]);
                    }
            }

        SDL_Flip(screen); //odświeżenie
    }

    EndUDP(); //koniec
    return 0;
}

Jeśli coś razi, to przepraszam, ale jeszcze się uczę ;)

EDIT #2:

Aha, i cały log kompilatora:


-------------- Build: Debug in SDLCom ---------------

Compiling: main.cpp
In file included from F:\Documents and Settings\Łukasz\Pulpit\Programming\ComProject I\SDLCom\/SDLUT_BASE.h:12:0,
                 from F:\Documents and Settings\Łukasz\Pulpit\Programming\ComProject I\SDLCom\main.cpp:15:
F:\Documents and Settings\Łukasz\Pulpit\Programming\ComProject I\SDLCom\/SDLUTNET.h: In function 'void newconnectionattempt(std::string, SDLNet_SocketSet)':
F:\Documents and Settings\Łukasz\Pulpit\Programming\ComProject I\SDLCom\/SDLUTNET.h:78:32: error: expected primary-expression before ',' token
F:\Documents and Settings\Łukasz\Pulpit\Programming\ComProject I\SDLCom\/SDLUTNET.h:78:32: error: 'SDL_reinterpret_cast' was not declared in this scope
In file included from F:\Documents and Settings\Łukasz\Pulpit\Programming\ComProject I\SDLCom\main.cpp:15:0:
F:\Documents and Settings\Łukasz\Pulpit\Programming\ComProject I\SDLCom\/SDLUT_BASE.h: In function 'void GAME_Init()':
F:\Documents and Settings\Łukasz\Pulpit\Programming\ComProject I\SDLCom\/SDLUT_BASE.h:2111:13: warning: unused variable 'bgsize' [-Wunused-variable]
F:\Documents and Settings\Łukasz\Pulpit\Programming\ComProject I\SDLCom\/SDLUT_BASE.h:2112:13: warning: unused variable 'totsize' [-Wunused-variable]
Process terminated with status 1 (0 minutes, 0 seconds)
2 errors, 2 warnings
 

EDIT #3:

  • wybrane procedury wymagane do skompilowania powyższego kodu, jakby ktoś się chciał pobawić:

SDL_Rect packpos(int x, int y) //Pakowanie jakiejkolwiek pozycji (x,y) do zmiennej SDL_Rect - oszczędza rozmiar tekstu
    {
        SDL_Rect xy;
        xy.x=x;
        xy.y=y;
        return xy;
    }

SDL_Color txtcolor;
TTF_Font *font;

void textcolor(int r, int g, int b) //Zmiana koloru tekstu 
    {
        txtcolor.r=r;
        txtcolor.g=g;
        txtcolor.b=b;
    }

void FontInit(const char* path, int size) //Inicjacja czcionki
    {
        TTF_Init();
        font=TTF_OpenFont(path, size);
        textcolor(255,255,255);
    }

void textwrite(int x, int y, string text) //Pisze tekst na ekranie
    {
        char const* writing=text.c_str();
        SDL_Surface* tx;
        tx=TTF_RenderText_Solid(font, writing, txtcolor);
        SDL_Rect fpos;
        fpos=packpos(x,y);
        SDL_BlitSurface(tx,0,screen,&fpos);
        SDL_FreeSurface(tx);
    }