[SOLVED] Plug-In Issue: SFML

Started by ladognome, Tue 16/07/2013 02:02:48

Previous topic - Next topic

ladognome

Hi everyone! So, this is the first time I'm posting something on this forum because I have finally given up.  :P
Anyway, I'm creating my first game in AGS, but first I'm making a plug-in that supports UDP networking. Because I'm crazy. (I have other reasons too, but don't worry: I can code. I just graduated with a degree in computer science! :-D )
I'm writing it in C++ using SFML, and it compiles correctly in Visual Studio 2010. However, when I include it in AGS Editor, the game gives me an error that it cannot parse 'sf', which is the namespace for the SFML functions (see http://www.sfml-dev.org/documentation/2.0/hierarchy.php). I have tried including the namespace sf in my code, but it yells at me. Is there anyone who is more familiar with C++ who can help me? (Or more experience writing plugins that use external dlls?)
Thanks!

Update: I got the plugin to compile while using namespace sf, but I still get the "parse error at 'sf'" from file "__Plugin100.ash"

Crimson Wizard

#1
I am sorry, this may be crazy, but from what you said I've got an idea that you are putting C++ syntax into AGSScript? Is it true, or I am just not fully awaken yet?

Anyway, can you show the contents of "__Plugin100.ash" please?

ladognome

#2
Oh sorry. No, I'm making an engine plugin. http://www.adventuregamestudio.co.uk/site/ags/plugins/engine/
I've been using the template they gave too.

I can't find that file. It's not in my AGS directory, my game's directory, or my code directory.
So I'll just attach my code so far. (But I probably messed up my pointers big time.)

[embed=425,349]// AGSMultiplayer.cpp
// This is the an engine plugin for Adventure Game Studio to enable multiplayer

#include "stdafx.h"
#include "AGSMultiplayer.h"

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

#define THIS_IS_THE_PLUGIN
#include "agsplugin.h"

#include <SFML/Network.hpp>
using namespace sf;

#pragma unmanaged
BOOL APIENTRY DllMain( HANDLE hModule,
   DWORD  ul_reason_for_call,
   LPVOID lpReserved) {

      switch (ul_reason_for_call)   {
      case DLL_PROCESS_ATTACH:
      case DLL_THREAD_ATTACH:
      case DLL_THREAD_DETACH:
      case DLL_PROCESS_DETACH:
         break;
      }
      return TRUE;
}
#pragma managed

// ***** DESIGN TIME CALLS *******
IAGSEditor *editor;

const char *ourScriptHeader =
   "import void SendData(sf::Packet, unsigned short);\r\n"
   "import int ReceiveData(sf::Packet, unsigned short);\r\n"
   "import sf::IpAddress getFriendIP(void);\r\n"
   "import void setFriendIP(sf::IpAddress);\r\n";

LPCSTR AGS_GetPluginName(void) {
   // Return the plugin description
   return "Network Multiplayer Plugin";
}

int  AGS_EditorStartup (IAGSEditor *lpEditor) {
   // User has checked the plugin to use it in their game

   // If it's an earlier version than what we need, abort.
   if (lpEditor->version < 1)
      return -1;

   editor = lpEditor;
   editor->RegisterScriptHeader (ourScriptHeader);

   // Return 0 to indicate success
   return 0;
}

void AGS_EditorShutdown () {
   // User has un-checked the plugin from their game
   editor->UnregisterScriptHeader (ourScriptHeader);
}

void AGS_EditorProperties (HWND parent) {
   // User has chosen to view the Properties of the plugin
   // We could load up an options dialog or something here instead
}

int AGS_EditorSaveGame (char *buffer, int bufsize) {
   // We don't want to save any persistent data
   return 0;
}

void AGS_EditorLoadGame (char *buffer, int bufsize) {
   // Nothing to load for this dummy plugin
}

// ******* END DESIGN TIME  *******


// ****** RUN TIME ********

IAGSEngine *engine;
sf::IpAddress myIP = sf::IpAddress::LocalHost;
sf::IpAddress friendIP;

// Your address in the world wide web (like 83.2.124.68 -- the one you get with www.whatismyip.org)
sf::IpAddress myWebIP = sf::IpAddress::getPublicAddress();

sf::IpAddress getFriendIP(void)
{
   return friendIP;
}
void setFriendIP(sf::IpAddress IP)
{
   friendIP = IP;
}

int SendData(sf::Packet packet, unsigned short port)
{
   // Create the UDP socket
   sf::UdpSocket Socket;

   //UDP socket
   //send (Packet &packet, const IpAddress &remoteAddress, unsigned short remotePort)
   if (friendIP == sf::IpAddress::None)
   {
      if (Socket.send(packet, friendIP, port) != sf::Socket::Done)
      {
         //Socket.unbind();
         return -1;
      }
      //Socket.unbind();
      return 0;
   }
   //Socket.unbind();
   return -1;
}

int ReceiveData(sf::Packet packet, unsigned short port)
{
   // Create the UDP socket
   sf::UdpSocket Socket;

   //bind it
   if (Socket.bind(port) != sf::Socket::Done)
   {
      Socket.unbind();
      return -1;
   }

   //UDP socket
   //receive (Packet &packet, IpAddress &remoteAddress, unsigned short &remotePort)
   if (Socket.receive(packet, friendIP, port) != sf::Socket::Done)
   {
      Socket.unbind();
      return -1;
   }
   //std::cout << "Received from " << friendIP << " on port " << port << std::endl;
   Socket.unbind();
   return 0;
}

void AGS_EngineStartup (IAGSEngine *lpEngine) {
   engine = lpEngine;

   // Make sure it's got the version with the features we need
   if (engine->version < 3) {
      engine->AbortGame ("Engine interface is too old. You need a newer version of AGS.");
   }

   engine->RegisterScriptFunction ("SendData", SendData);
   engine->RegisterScriptFunction ("ReceiveData", ReceiveData);
   engine->RegisterScriptFunction ("setFriendIP", setFriendIP);
   engine->RegisterScriptFunction ("getFriendIP", getFriendIP);
   engine->RequestEventHook (AGSE_SAVEGAME);
}

void AGS_EngineShutdown() {
   // no work to do here - but if we had created any dynamic sprites,
   // we should delete them here
}

int AGS_EngineOnEvent (int event, int data) {
   //events are AGSE_*
   if (event == AGSE_SAVEGAME) {
  }
  return 0;
}

// *** END RUN TIME ****
[/embed]

Terrorcell

#3
First thing I noticed was:
Code: AGS

const char *ourScriptHeader =
"import void SendData(sf::Packet, unsigned short);\r\n"
"import int ReceiveData(sf::Packet, unsigned short);\r\n"
"import sf::IpAddress getFriendIP(void);\r\n"
"import void setFriendIP(sf::IpAddress);\r\n";


That part of the plugin is supposed to follow AGSScript syntax. It's used to create the script representation of your plugin's features.
Therefore, because AGSScript doesn't support namespaces, 'sf::Packet' and 'sf::IpAddress' will cause syntax errors. You're going to have to find a way to get past the use of 'sf::'.

ladognome

Ahh! That'll do it. I'll fiddle around with that, and see what I can do. Thanks a bunch!

ladognome

Yep it worked! Now I'm just getting pointer errors... :P Thanks again!

SMF spam blocked by CleanTalk