Jump to content

gamecreator

Members
  • Posts

    4,937
  • Joined

  • Last visited

Everything posted by gamecreator

  1. Here is the data transfer code sample. It very directly just starts sending and receiving coordinates with a Steam friend and moves two names on screen accordingly. As before, create a new project and replace everything in App.cpp with this code. Make sure to change yoursteamname and otherplayersteamname in friendstrings to your Steam name and your friend's Steam name. The program matches your Steam friend based on the exact name you specify. #include "App.h" using namespace Leadwerks; App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {} App::~App() { delete world; delete window; } bool steamfriendfound = false; // Change yoursteamname and otherplayersteamname to your and other player's actual Steam names // Matching system depends on other player's name being spelled correctly char *friendstrings[2] = { "yoursteamname", "otherplayersteamname" }; int thisplayerindex = 0; CSteamID steamIDFriend; struct posdatastruct { float x, y; } pos[2]; bool App::Start() { window = Leadwerks::Window::Create("SteamTest"); context = Context::Create(window); world = World::Create(); camera = Camera::Create(); window->HideMouse(); Steamworks::Initialize(); // Set initial positions of 2 players pos[0].x=200; pos[0].y=200; pos[1].x=400; pos[1].y=400; return true; } bool App::Loop() { if(!SteamAPI_IsSteamRunning()) { MessageBoxA(0, "Steam not detected. Please run Steam before running this program.", "Error", 0); return false; } // Compare current player's name // If it's the same as the second player (index 1), set it as such // (otherwise leave it index 0) if(strcmp(friendstrings[1],SteamFriends()->GetFriendPersonaName(SteamUser()->GetSteamID()))==0) thisplayerindex=1; // If we haven't found the friend we want to connect to yet... if(!steamfriendfound) { // Cycle through all of your Steam friends for(int i = 0; i < SteamFriends()->GetFriendCount(k_EFriendFlagImmediate); i++) { // Get friend ID steamIDFriend = SteamFriends()->GetFriendByIndex(i, k_EFriendFlagImmediate); // Match connecting player by Steam name if(strcmp(friendstrings[1-thisplayerindex], SteamFriends()->GetFriendPersonaName(steamIDFriend))==0) { steamfriendfound=true; break; } } } // ... otherwise play the game else { // Send data to friend SteamNetworking()->SendP2PPacket(steamIDFriend, &pos[thisplayerindex], sizeof(pos[0]), k_EP2PSendUnreliable); // Read any and all incoming packets uint32 msgSize = 0; while(SteamNetworking()->IsP2PPacketAvailable(&msgSize)) { void *packet = malloc(msgSize); CSteamID steamIDRemote; uint32 bytesRead = 0; // At least make sure message is the right size if(msgSize==sizeof(pos[0])) { if(SteamNetworking()->ReadP2PPacket(&pos[1-thisplayerindex], msgSize, &bytesRead, &steamIDRemote)) { // Any extra code to analyze the packet can go here } } free(packet); } } // Exit program if needed if(window->KeyHit(Key::Escape)||window->Closed()) return false; if(window->KeyDown(Key::Right)) pos[thisplayerindex].x+=2*Time::GetSpeed(); if(window->KeyDown(Key::Left)) pos[thisplayerindex].x-=2*Time::GetSpeed(); if(window->KeyDown(Key::Up)) pos[thisplayerindex].y-=2*Time::GetSpeed(); if(window->KeyDown(Key::Down)) pos[thisplayerindex].y+=2*Time::GetSpeed(); Leadwerks::Time::Update(); world->Update(); world->Render(); context->SetBlendMode(Blend::Alpha); context->SetColor(1, 1, 1); context->DrawText("Use the arrow keys to move your name", 10, 10); context->DrawText(friendstrings[0], (int)pos[0].x, (int)pos[0].y); context->DrawText(friendstrings[1], (int)pos[1].x, (int)pos[1].y); context->SetBlendMode(Blend::Solid); context->Sync(false); // Sleep a bit to not spam connection Sleep(10); return true; } Interesting thing to note: I thought I was being clever by making sure both players are running Steam AppID 480 (our defaul pre-Greenlit game ID). This backfired when my friend was already in another game before running this program. The AppID didn't match because Steam returned the ID of his other game. (It also showed that game on my friend's list, not Spacewar.) As such, I removed that check and not too surprisingly, the program worked anyway. It seems Steam makes sure to send messages between the same games anyway, no matter what else you may have running, so you don't need to bother checking for it. Enjoy!
  2. http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/shape/shapepolymesh-r523
  3. Also http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/surface/
  4. Panther, you can do this right now without being Greenlit. Except for the initialization function it's all done using the Steamworks SDK and I'm not sure if they support Lua (I don't believe so but I'd check their page to make sure). I should also mention that before being Greenlit your game will always be AppID 480 and be called Spacewar. This can't be changed until you're Greenlit (per here).
  5. Completely agreed. This is an example that's as simple as I could make it to illustrate several Steam functions and be easy to understand. This is definitely not how you would code for public release. It's just a code snippet.
  6. Hi all! I spent the last few days, after work, learning how Steam code works and incorporating it into a small example project. I learned a bit and thought I'd share with the community, as I would personally have loved to use code like this as a starting point. I hope it helps someone. Explanation of what this all does is after the code. Simply start a new 3.1 C++ project and replace all the code in App.cpp with the below. #include "App.h" using namespace Leadwerks; App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {} App::~App() { delete world; delete window; } bool App::Start() { window = Leadwerks::Window::Create("SteamTest"); context = Context::Create(window); world = World::Create(); camera = Camera::Create(); window->HideMouse(); // Initialize Steamworks Steamworks::Initialize(); return true; } bool App::Loop() { if(!SteamAPI_IsSteamRunning()) { MessageBoxA(0, "Steam not detected. Please run Steam before running this program.", "Error", 0); return false; } // Exit program if needed if(window->KeyHit(Key::Escape) || window->Closed()) return false; Leadwerks::Time::Update(); world->Update(); world->Render(); context->SetBlendMode(Blend::Alpha); context->SetColor(1, 1, 1); // Go to a website using STEAM browser if(window->KeyHit(Key::W)) SteamFriends()->ActivateGameOverlayToWebPage("http://www.leadwerks.com/"); // Send a message to the first friend on the list (index 0) using STEAM if(window->KeyHit(Key::M)) SteamFriends()->ReplyToFriendMessage(SteamFriends()->GetFriendByIndex(0, k_EFriendFlagImmediate), "Test from program"); context->DrawText("Your user name: ", 10, 30); context->DrawText(SteamFriends()->GetFriendPersonaName(SteamUser()->GetSteamID()), 120, 30); FriendGameInfo_t friendgameinfo; context->DrawText("This game's SteamID: ", 10, 50); SteamFriends()->GetFriendGamePlayed(SteamUser()->GetSteamID(), &friendgameinfo); context->DrawText(String(friendgameinfo.m_gameID.AppID()), 140, 50); int steamfriends = SteamFriends()->GetFriendCount(k_EFriendFlagImmediate); context->DrawText("Friends: " + String(steamfriends), 10, 90); // Cycle through all of your Steam friends for (int i = 0; i < steamfriends; i++) { // Get friend ID CSteamID steamIDFriend = SteamFriends()->GetFriendByIndex(i, k_EFriendFlagImmediate); // Print friend name context->DrawText(SteamFriends()->GetFriendPersonaName(steamIDFriend), 10, 110 + i * 20); // Print friend's Steam status (Offline, Online, Away, etc.) if(SteamFriends()->GetFriendPersonaState(steamIDFriend) == k_EPersonaStateOffline) context->DrawText("Offline", 120, 110 + i * 20); if(SteamFriends()->GetFriendPersonaState(steamIDFriend) == k_EPersonaStateOnline) context->DrawText("Online", 120, 110 + i * 20); if(SteamFriends()->GetFriendPersonaState(steamIDFriend) == k_EPersonaStateBusy) context->DrawText("Busy", 120, 110 + i * 20); if(SteamFriends()->GetFriendPersonaState(steamIDFriend) == k_EPersonaStateAway) context->DrawText("Away", 120, 110 + i * 20); if(SteamFriends()->GetFriendPersonaState(steamIDFriend) == k_EPersonaStateSnooze) context->DrawText("Snooze", 120, 110 + i * 20); // Is friend playing a Steam game right now? if(SteamFriends()->GetFriendGamePlayed(steamIDFriend, &friendgameinfo)) // SteamID of game they're playing, if they're in one context->DrawText(String(friendgameinfo.m_gameID.AppID()),220,110 + i * 20); else context->DrawText("Not in game", 200, 110 + i * 20); // Match a player by name if(strcmp("yourfriendssteamplayername", SteamFriends()->GetFriendPersonaName(SteamFriends()->GetFriendByIndex(i, k_EFriendFlagImmediate))) == 0) { context->DrawText("Player name match", 300, 110 + i * 20); // Do something here like start sending him data... } } context->SetBlendMode(Blend::Solid); context->Sync(false); return true; } This code is an illustration of several things you can do with Steam: If you hit M, it sends a message to the first person on your list (using index 0 in the function). If they're offline then they will receive the message(s) when they get online. I realize the function is called ReplyToFriendMessage but I couldn't find one that was just Send and this was tested and it works, even if it's not a reply (it's the first message sent). If you hit W, it opens a browser inside your game and goes to the website specified. It shows your own Steam name and the Steam AppID of your game (by default it's 480). It shows the total count of your friends on your friends list. Then it cycles through all your friends and displays their name, their Steam status and if they're in a game, the AppID of the game they're in. This is very useful in dealing with only friends that are online and only sending data to people who are already in the same game as you are, if you want to send data directly (not by lobby invite). A lot of this was learned by simply seeing what functions existed but a lot more was by wading through the documentation here: https://partner.steamgames.com/home/steamworks Next up: peer-to-peer networking. Will report back with any success.
  7. There may be more but are the non-numpad number keys (above the letters) supposed to be declared in Key.h? It looks like a lot of this file was commented out for Lua. Here's what Key.h looks like now. #pragma once #include "../../Leadwerks.h" namespace Leadwerks { class Key //lua { public: static const int Alt,BackSpace,CapsLock,ControlKey,Delete,Down,End,Enter,Escape,Home,Insert,Left;//lua static const int NumLock,PageDown,PageUp,RControlKey,Right,Shift,Space,Subtract,Tab,Up; //lua static const int Tilde,Equals,OpenBracket,CloseBracket,Backslash,Semicolon,Quotes,Comma,Period,Slash,WindowsKey; //lua static const int LButton,MButton,RButton,XButton1,XButton2; //lua static const int F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12;//lua //static const int a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z; static const int A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z;//lua static const int D0, D1, D2, D3, D4, D5, D6, D7, D8, D9;//lua static const int NumPad0, NumPad1, NumPad2, NumPad3, NumPad4, NumPad5, NumPad6, NumPad7, NumPad8, NumPad9,NumPadPeriod,NumPadDivide,NumPadMultiply,NumPadSubtract,NumPadAddition;//lua }; /* enum{ MOUSE_LEFT=1, MOUSE_RIGHT=2, MOUSE_MIDDLE=3 }; enum{ MODIFIER_NONE=0, MODIFIER_SHIFT=1, MODIFIER_CONTROL=2, MODIFIER_OPTION=4, MODIFIER_SYSTEM=8, MODIFIER_ALT=MODIFIER_OPTION, MODIFIER_MENU=MODIFIER_OPTION, MODIFIER_APPLE=MODIFIER_SYSTEM, MODIFIER_WINDOWS=MODIFIER_SYSTEM }; enum{ KEY_ESCAPE=27, KEY_BACKSPACE=8,KEY_TAB, KEY_ENTER=13, KEY_SPACE=32, KEY_PAGEUP=33,KEY_PAGEDOWN,KEY_END,KEY_HOME, KEY_LEFT=37,KEY_UP,KEY_RIGHT,KEY_DOWN, KEY_INSERT=45,KEY_DELETE, KEY_0=48,KEY_1,KEY_2,KEY_3,KEY_4,KEY_5,KEY_6,KEY_7,KEY_8,KEY_9, KEY_A=65,KEY_B,KEY_C,KEY_D,KEY_E,KEY_F,KEY_G,KEY_H,KEY_I,KEY_J, KEY_K,KEY_L,KEY_M,KEY_N,KEY_O,KEY_P,KEY_Q,KEY_R,KEY_S,KEY_T, KEY_U,KEY_V,KEY_W,KEY_X,KEY_Y,KEY_Z, KEY_LSYS=91,KEY_RSYS, KEY_NUM0=96,KEY_NUM1,KEY_NUM2,KEY_NUM3,KEY_NUM4, KEY_NUM5,KEY_NUM6,KEY_NUM7,KEY_NUM8,KEY_NUM9, KEY_NUMMULTIPLY=106,KEY_NUMADD,KEY_NUMSLASH, KEY_NUMSUBTRACT,KEY_NUMDECIMAL,KEY_NUMDIVIDE, KEY_F1=112,KEY_F2,KEY_F3,KEY_F4,KEY_F5,KEY_F6, KEY_F7,KEY_F8,KEY_F9,KEY_F10,KEY_F11,KEY_F12, KEY_LSHIFT=160,KEY_RSHIFT, KEY_LCONTROL=162,KEY_RCONTROL, KEY_LALT=164,KEY_RALT, KEY_TILDE=192,KEY_MINUS=189,KEY_EQUALS=187, KEY_OPENBRACKET=219,KEY_CLOSEBRACKET=221,KEY_BACKSLASH=226, KEY_SEMICOLON=186,KEY_QUOTES=222, KEY_COMMA=188,KEY_PERIOD=190,KEY_SLASH=191 };*/ } I have a C++ project in 3.1.
  8. Of course, if it's recorded at a high enough framerate you can slow it down yourself. There are other methods but with Firefox, download Download Helper extension or something similar and it will allow you to download the video to your computer. Then watch the video and use a slow playback to see it at a slower speed, maybe even the original speed. Just a thought.
  9. Josh, you should make a suggestion thread too. Maybe that developer guy would listen to you.
  10. Considering your list, I wonder what positions the rest of the team would be handling.
  11. http://www.leadwerks.com/werkspace/blog/41/entry-1156-leadwerks-31-pre-orders-now-available-indie-edition-coming-to-steam-january-6th/
  12. I thought I saw this somewhere before (though a search didn't result in anything) but how do you have Steam recognize your game as something other than Spacewar? I'm pretty sure this has something to do with the app id but don't remember if there was a solution. Did this require a Greenlight?
  13. The white text blocks look like you didn't set the blend mode to Alpha before drawing the text. See this example: http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/context/contextdrawtext-r731
  14. I guess it's time to upgrade. http://www.leadwerks.com/werkspace/topic/9322-vs2013-needed/
  15. Now I'm getting this but I think I'll be able to figure it out:
  16. Aww hell. I'm an idiot. I had Lua selected instead of C++ when creating a project.
  17. 3.1 Standard Steam Edition I created a new project and opened its folder through the project manager (which opened C:\Leadwerks\Project\MyNewProject). Before there used to be a Projects folder which had the various Windows/Android/iOS/Mac folders in it but I don't see that any more. Any idea why this isn't generated? I'm trying to open the vcxproj file...
  18. Wait... right now? Where can we find the functions to use? Are they in the header? (They're not in the documentation yet.)
  19. I figure this is just a bonus. I'm sure the actual Leadwerks networking will be Steam independent as there is also a non-Steam edition to support.
  20. I also created a very basic project cleaner to delete files you don't want http://www.leadwerks.com/werkspace/files/file/509-le3-project-cleaner-with-source/
  21. Hell yes. I'm sure I'm not the only one eagerly waiting to play with this. The obvious question is when but I assume there's no timeframe yet. Much more importantly, is there a required process? Let's say you make a barebones program that in theory connects to a friend and sends an integer. Can you and your friend try it out immediately or is there some sort of Steam authorization process to go through? Or does your project need to be at least Greenlit? Also, can savegames and other data be stored on the Steam cloud?
  22. Thanks. Did you have a moment to take a look at the project? Does it happen to you as well with 3.0? Understood. Just matching the editor would be great. Edit: it actually looks like either the map didn't load the light (and so is using a global one) or didn't make it dynamic. I'm going to try taking it out of the scene and creating it via code.
×
×
  • Create New...