本文整理汇总了C++中SDLNet_Init函数的典型用法代码示例。如果您正苦于以下问题:C++ SDLNet_Init函数的具体用法?C++ SDLNet_Init怎么用?C++ SDLNet_Init使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDLNet_Init函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: NET_SDL_InitClient
static boolean NET_SDL_InitClient(void)
{
int p;
//!
// @category net
// @arg <n>
//
// Use the specified UDP port for communications, instead of
// the default (2342).
//
p = M_CheckParm("-port");
if (p > 0)
port = atoi(myargv[p+1]);
SDLNet_Init();
udpsocket = SDLNet_UDP_Open(0);
if (udpsocket == NULL)
{
I_Error("NET_SDL_InitClient: Unable to open a socket!");
}
recvpacket = SDLNet_AllocPacket(1500);
#ifdef DROP_PACKETS
srand(time(NULL));
#endif
return true;
}
示例2: LOGE
void Platform::init()
{
m_done = false;
if(SDL_Init(SDL_INIT_EVERYTHING))
{
LOGE("Unable to initialize SDL");
return;
}
SDLNet_Init();
m_rootWidget = new UIWidget();
m_rootWidget->setPhantom(true);
m_rootWidget->setId("RootWidget");
m_focusWidget = nullptr;
m_grabWidget = nullptr;
m_hoveredWidget = nullptr;
for(uint8_t i = 0; i < 6; i++)
{
m_mousePressed[i] = false;
m_mousePosition[i] = {0, 0};
m_mouseLastPosition[i] = {0, 0};
m_mouseClickPosition[i] = {0, 0};
}
m_offsetPosition = {0, 0};
g_core.init();
}
示例3: net_init
void net_init(void) {
if (SDLNet_Init() < 0) {
error("Could not initialize SDL Net: %s\n", SDLNet_GetError());
}
}
示例4: setup_server
/* Setup TCP Server, and wait for a single
* client to connect */
int setup_server(unsigned port) {
#if !defined(PSP) && !defined(EMSCRIPTEN) && !defined(DREAMCAST) && !defined(THREE_DS)
is_server = 1;
log_message(LOG_INFO, "Starting server on port %u\n",port);
//SDL_INIT(SDL_INIT_EVERYTHING);
SDLNet_Init();
IPaddress ip;
SDLNet_ResolveHost(&ip, NULL, port);
server = SDLNet_TCP_Open(&ip);
log_message(LOG_INFO, "Waiting for client to connect\n");
while (client == NULL) {
client = SDLNet_TCP_Accept(server);
SDL_Delay(1000);
}
const char * message = "Welcome to GB server";
SDLNet_TCP_Send(client, message, strlen(message) + 1);
log_message(LOG_INFO, "Client successfully connected\n");
socketset = SDLNet_AllocSocketSet(1);
SDLNet_TCP_AddSocket(socketset, client);
connection_up = 1;
return 1;
#endif
return 0;
}
示例5: setup_client
/* Setup TCP Client, and attempt to connect
* to the server */
int setup_client(unsigned port) {
#if !defined(PSP) && !defined(EMSCRIPTEN) && !defined(DREAMCAST) && !defined(THREE_DS)
is_client = 1;
log_message(LOG_INFO, "Attempting to connect to server on port %u\n",port);
//SDL_INIT(SDL_INIT_EVERYTHING);
SDLNet_Init();
IPaddress ip;
//TODO, for now always connect to localhost, fix for any specified ip in
//the future
SDLNet_ResolveHost(&ip, "localhost", port);
client = SDLNet_TCP_Open(&ip);
socketset = SDLNet_AllocSocketSet(1);
char buf[100];
int i = SDLNet_TCP_Recv(client, buf, 100);
for (int j = 0; j < i; j++) {
printf("%c",buf[j]);
}
printf("\n");
SDLNet_TCP_AddSocket(socketset, client);
connection_up = 1;
return 1;
#endif
return 0;
}
示例6: selected
void NetworkManager::NetworkClient(char* str) //http://content.gpwiki.org/index.php/SDL:Tutorial:Using_SDL_net <- good code here, adapt messages accordingly
{ //http://jcatki.no-ip.org:8080/SDL_net/SDL_net.html <- good documentation here
IPaddress ip; /* Call this function once client is selected (after accepting a host if that is possible via GUI) */
int len;
char buffer[512];
server = false;
host=str; //If a GUI - entered host name is possible, add it to the function arguments and set this to it.
if (SDLNet_Init() < 0)
{
fprintf(stderr, "SDLNet_Init: %s\n", SDLNet_GetError());
exit(EXIT_FAILURE);
}
/* Resolve the host we are connecting to */
if (SDLNet_ResolveHost(&ip, host, 2000) < 0)
{
fprintf(stderr, "SDLNet_ResolveHost: %s\n", SDLNet_GetError());
exit(EXIT_FAILURE);
}
/* Open a connection with the IP provided (listen on the host's port) */
if (!(targetSocket = SDLNet_TCP_Open(&ip)))
{
fprintf(stderr, "SDLNet_TCP_Open: %s\n", SDLNet_GetError());
exit(EXIT_FAILURE);
}
}
示例7: init
void init(int argc, char *argv[])
{
/* interpret command line arguments */
if ( argc < 3 ) throw "Usage: server <config_file> <port> [<log_file>]";
/* local port */
sscanf( argv[2], "%d", &local_port);
if ( local_port < 1 ) throw "The port must be an integer larger than 0";
printf( "Starting server on port %d\n", local_port );
srand( (unsigned int)time(NULL) );
/*
if ( SDL_Init( SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE ) < 0 ) // |SDL_INIT_VIDEO
{
printf("Could not initialize SDL: %s.\n", SDL_GetError());
throw "Failed to initialize SDL (SDL_Init)";
}*/
if ( SDLNet_Init() < 0 ) throw "Failed to initialize SDL_net (SDLNet_Init)";
/* initialize server data */
sd = new ServerData( argv[1] ); assert( sd );
sd->log_file = ( argc >= 4 ) ? argv[3] : NULL;
sd->wm.generate();
}
示例8: SDLNet_Init
bool MainApp::onLoadWorld()
{
m_pFontTexture = peon::EngineCore::getSingleton().getRenderer()->loadTexture("data\\textures\\font.png");
m_pFont = peon::EngineCore::getSingleton().getRenderer()->loadFont(16, 16, 14);
SDLNet_Init();
m_port = 9090;
// Resolve the argument into an IPaddress type
if(SDLNet_ResolveHost(&m_hostAddress,NULL,m_port)==-1)
{
return false;
}
// open the server socket
m_hostSocket = SDLNet_TCP_Open(&m_hostAddress);
if(!m_hostSocket)
{
//printf("SDLNet_TCP_Open: %s\n",SDLNet_GetError());
//exit(4);
return false;
}
return true;
}
示例9: LOG_MSG
TCPClientSocket::TCPClientSocket(TCPsocket source) {
#ifdef NATIVESOCKETS
nativetcpstruct=0;
#endif
sendbuffer=0;
isopen = false;
if(!SDLNetInited) {
if(SDLNet_Init()==-1) {
LOG_MSG("SDLNet_Init failed: %s\n", SDLNet_GetError());
return;
}
SDLNetInited = true;
}
mysock=0;
listensocketset=0;
if(source!=0) {
mysock = source;
listensocketset = SDLNet_AllocSocketSet(1);
if(!listensocketset) return;
SDLNet_TCP_AddSocket(listensocketset, source);
isopen=true;
}
}
示例10: network_init
int network_init() {
int r = SDLNet_Init();
if (r) {
std::cerr << "Error initializing network functionality: " << SDLNet_GetError() << "\n";
}
return r;
}
示例11: initSdlNet
bool UdpConnection::initSdlNet() {
if (SDLNet_Init() == -1) {
std::cout << "SDL_Net could not initialize: " << SDLNet_GetError() << std::endl;
return false;
}
return true;
}
示例12: initSDL
void initSDL(void){
SDL_Init(SDL_INIT_VIDEO);
gWindow = SDL_CreateWindow("Battlecave", SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED, SCREENWIDTH, SCREENHEIGHT, SDL_WINDOW_SHOWN);
if(gWindow == NULL){
printf("Window creation failed!\n");
exit(EXIT_FAILURE);
}
gRenderer = SDL_CreateRenderer(gWindow, -1, SDL_RENDERER_ACCELERATED);
if(gRenderer == NULL){
printf("Renderer creation failed!\n");
exit(EXIT_FAILURE);
}
if(TTF_Init() < 0){
printf("TTF Init failed!\n");
exit(EXIT_FAILURE);
}
if(SDLNet_Init() < 0){
printf("SDL Net Init failed!\n");
exit(EXIT_FAILURE);
}
SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF);
return;
}
示例13: error
void OSystem_SDL::initSDL() {
// Check if SDL has not been initialized
if (!_initedSDL) {
// We always initialize the video subsystem because we will need it to
// be initialized before the graphics managers to retrieve the desktop
// resolution, for example. WebOS also requires this initialization
// or otherwise the application won't start.
uint32 sdlFlags = SDL_INIT_VIDEO;
if (ConfMan.hasKey("disable_sdl_parachute"))
sdlFlags |= SDL_INIT_NOPARACHUTE;
// Initialize SDL (SDL Subsystems are initiliazed in the corresponding sdl managers)
if (SDL_Init(sdlFlags) == -1)
error("Could not initialize SDL: %s", SDL_GetError());
_initedSDL = true;
}
#ifdef USE_SDL_NET
// Check if SDL_net has not been initialized
if (!_initedSDLnet) {
// Initialize SDL_net
if (SDLNet_Init() == -1)
error("Could not initialize SDL_net: %s", SDLNet_GetError());
_initedSDLnet = true;
}
#endif
}
示例14: fprintf
void Server::Init()
{
/* Initialize SDL_net */
if (SDLNet_Init() < 0)
{
fprintf(stderr, "SDLNet_Init: %s\n", SDLNet_GetError());
exit(EXIT_FAILURE);
}
/* Open a socket */
if (!(sd = SDLNet_UDP_Open(7777)))
{
fprintf(stderr, "SDLNet_UDP_Open: %s\n", SDLNet_GetError());
exit(EXIT_FAILURE);
}
/* Make space for the packet */
if (!(p = SDLNet_AllocPacket(sizeof(Transform))))
{
fprintf(stderr, "SDLNet_AllocPacket: %s\n", SDLNet_GetError());
exit(EXIT_FAILURE);
}
/* Wait for a connection, send data and term */
quit = 0;
}
示例15: fprintf
void NetworkManager::NetworkHost(void) //http://content.gpwiki.org/index.php/SDL:Tutorial:Using_SDL_net <- good code here, adapt messages accordingly
{ //http://jcatki.no-ip.org:8080/SDL_net/SDL_net.html <- good documentation here
TCPsocket sd; /* Call this function once Host button is selected */
IPaddress ip;
char buffer[512];
server = true;
if (SDLNet_Init() < 0)
{
fprintf(stderr, "SDLNet_Init: %s\n", SDLNet_GetError());
exit(EXIT_FAILURE);
}
/* Resolving the host using NULL make network interface to listen */
if (SDLNet_ResolveHost(&ip, NULL, 2000) < 0)
{
fprintf(stderr, "SDLNet_ResolveHost: %s\n", SDLNet_GetError());
exit(EXIT_FAILURE);
}
/* Open a connection with the IP provided (listen on the host's port) */
if (!(sd = SDLNet_TCP_Open(&ip)))
{
fprintf(stderr, "SDLNet_TCP_Open: %s\n", SDLNet_GetError());
exit(EXIT_FAILURE);
}
/* Wait for a connection*/
while (!(targetSocket = SDLNet_TCP_Accept(sd)))
{
}
std::cout<<"accepted client";
}