Rob Janes Posted January 31, 2011 Author Share Posted January 31, 2011 This tutorial will let you add weather, (Snow/Rain) to your Eclipse Engine. It will require modifications both Client and Server Side. Let's get started shall we?**1\. Server Side Changes**We need to declare Weather on the server, this can be done with a string, integer, just something to identify what the current weather is, I use a string as I use the 'name' of the weather to send to players later.In modTypes add```Public Weather As String```in modEnumerations add this to the server packets.```SSendWeather```Add this new Sub into modServerTCP```Sub SendWeather(ByVal index As Long)Dim buffer As clsBuffer Set buffer = New clsBuffer buffer.WriteLong SSendWeather buffer.WriteString Weather SendDataTo index, buffer.ToArray() Set buffer = Nothing Call PlayerMsg(index, "Current Weather: " & Weather, BrightCyan)End Sub```Add 3 Buttons on frmMain, called cmdSun, cmdRain and cmdSnow, these are the commands to change the Weather on dynamically through the Server.```Private Sub cmdRain_Click()Weather = "Rain"Dim I As IntegerFor I = 1 To MAX_PLAYERS If IsPlaying(I) Then Call SendWeather(I) End IfNext IEnd SubPrivate Sub cmdSnow_Click()Weather = "Snow"Dim I As IntegerFor I = 1 To MAX_PLAYERS If IsPlaying(I) Then Call SendWeather(I) End IfNext IEnd SubPrivate Sub cmdSun_Click()Weather = "Sun"Dim I As IntegerFor I = 1 To MAX_PLAYERS If IsPlaying(I) Then Call SendWeather(I) End IfNext IEnd Sub```Add this into modPlayer, Sub JoinGame after SendWelcome```'Send Weather Call SendWeather(index)```This concludes server-side adjustments–--------------------------------------------------------------------------------**2\. Client Side Adjustments**First we are going to use a new Font for the Weather so in modFonts just after it declares ChatFont add```Public WeatherFont As Long```We are going to add some declarations now, I used a custom module but you can add it anywhere at the beginning of existing modules.```Public Const WEATHER_DROPS = 250Public Const SUN = 1Public Const RAIN = 2Public Const SNOW = 3Public Type DropData x As Integer y As Integer strText As StringEnd TypePublic Drop(1 To WEATHER_DROPS) As DropDataPublic Weather As Integer```We're now going to add Subs to initilize the Weather system, and also a custom RandomNumber Function. Add this to any module, again, I used a custom module.```Function RandomNumber(Lowerbound As Long, Upperbound As Long)RandomizeRandomNumber = Int(Rnd * Upperbound) + LowerboundEnd FunctionPublic Sub InitWeather()Dim I As IntegerFor I = 1 To WEATHER_DROPSDrop(I).x = RandomNumber(1, 800)Drop(I).y = RandomNumber(1, 600)Next IEnd Sub```Add a Timer on frmMain, with an Interval of 50 and call it tmrUpdateWeather```Dim I As IntegerFor I = 1 To WEATHER_DROPS Drop(I).y = Drop(I).y + Int(RandomNumber(1, 5)) If Drop(I).y > 600 Then Drop(I).y = 0 Drop(I).x = Int(RandomNumber(-100, 900)) End If If Weather = RAIN Then Drop(I).x = Drop(I).x + Int(RandomNumber(1, 1)) End IfNext IIf Weather = SNOW ThentmrUpdateWeather.Interval = 50End IfIf Weather = RAIN ThentmrUpdateWeather.Interval = 20End If```In modText, in the SetFont Mod, we are now going to define the font we use for the weather```WeatherFont = CreateFont(24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "Arial")```Still in modText, add the following subs```' GDI text drawing onto bufferPublic Sub DrawWeather(ByVal hdc As Long, ByVal x, ByVal y, ByVal text As String, color As Long) Call SelectObject(hdc, WeatherFont) Call SetBkMode(hdc, vbTransparent) Call SetTextColor(hdc, 0) Call TextOut(hdc, x + 1, y + 1, text, Len(text)) Call SetTextColor(hdc, color) Call TextOut(hdc, x, y, text, Len(text))End SubPublic Sub DrawRain()Dim DropID As IntegerFor DropID = 1 To WEATHER_DROPSDrop(DropID).strText = "'"Call DrawWeather(TexthDC, Camera.Left + Drop(DropID).x, Camera.top + Drop(DropID).y, Drop(DropID).strText, &HFFFFC0)Next DropIDEnd SubPublic Sub DrawSnow()Dim DropID As IntegerFor DropID = 1 To WEATHER_DROPSDrop(DropID).strText = "*"Call DrawWeather(TexthDC, Camera.Left + Drop(DropID).x, Camera.top + Drop(DropID).y, Drop(DropID).strText, vbWhite)Next DropIDEnd Sub```In modGeneral, sub Main, we need to get the Weather 'engine' going. Add this to the start of Sub Main``` 'Set Default Weather to Sun InitWeather Weather = SUN```In modDirectDraw7 under the Render Graphics Sub, Add the following just after it defines TexthDC```If Weather = RAIN Then DrawRain End If If Weather = SNOW Then DrawSnow End If```In modEnumerations add this to the ServerPackets```SSendWeather```In modHandleData, in the InitMessages Sub, add this at the bottom.```HandleDataSub(SSendWeather) = GetAddress(AddressOf HandleWeather)```In modHandleData add the new Sub```Private Sub HandleWeather(ByVal Index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long) Dim Buffer As clsBuffer Dim strWeather As String Set Buffer = New clsBuffer Buffer.WriteBytes Data() strWeather = Buffer.ReadString Set Buffer = Nothing If strWeather = "Sun" Then Weather = SUN End If If strWeather = "Rain" Then Weather = RAIN End If If strWeather = "Snow" Then Weather = SNOW End IfEnd Sub```End of Client Side Changes–--------------------------------------------Once you compile, you will now be able to click the new buttons on your server and change the weather! Link to comment Share on other sites More sharing options...
Rob Janes Posted January 31, 2011 Author Share Posted January 31, 2011 You may want to change MAX_PLAYERS to Players_HighIndex with 1.3 Link to comment Share on other sites More sharing options...
evilbunnie Posted January 31, 2011 Share Posted January 31, 2011 Love it man, good job. Link to comment Share on other sites More sharing options...
Marsh Posted January 31, 2011 Share Posted January 31, 2011 Good to see more tutorials being made :), great job. Link to comment Share on other sites More sharing options...
mitlark Posted January 31, 2011 Share Posted January 31, 2011 Excellent tutorial, I will see it carefully for learning purposes (and of course, because WeatherControls are cool xD). Although I will try to use an integer instead of a string for the Weather declaration.Great work :),L'ark Mitsinikos Link to comment Share on other sites More sharing options...
Rob Janes Posted January 31, 2011 Author Share Posted January 31, 2011 Yeah, I had an Integer first, it's easier that way, I used a string so when I do "SendWeather" it sends a message to every player with "Current Weather: " and the WeatherString here. Just coder preferences that's all! I'll post more tutorials soon. Link to comment Share on other sites More sharing options...
Dzastin Posted January 31, 2011 Share Posted January 31, 2011 Private Sub cmdRain_Click()Weather = "Deszcz"Dim I As IntegerFor I = 1 To MAX_PLAYERS If IsPlaying(I) Then Call SendWeather(I) End IfNext IEnd Sub''Variable not defined'' Link to comment Share on other sites More sharing options...
Rob Janes Posted January 31, 2011 Author Share Posted January 31, 2011 That should readWeather = "Rain"NOTWeather = "Deszcz"The code snipped says Rain, did you change it by mistake? Link to comment Share on other sites More sharing options...
Rob Janes Posted January 31, 2011 Author Share Posted January 31, 2011 Also, it's saying the Weather variable isn't defined.Did you addPublic Weather As StringAt the beginning of modTypes? Link to comment Share on other sites More sharing options...
erkro1 Posted January 31, 2011 Share Posted January 31, 2011 Great job!Gonna test it right now ;) Link to comment Share on other sites More sharing options...
Robin Posted January 31, 2011 Share Posted January 31, 2011 You do realise that drawing text is one of the worst things you can do to slow down your game? I'm being serious. Do an FPS test before you turn on your rain/snow then do an FPS test after. With the lock off. There's a reason I try and minimise text rendering, to the point where I'm actually considering a bitmap font or pre-rendering to surfaces.BltFast would be 100x easier to do and 1000x faster in practice. Link to comment Share on other sites More sharing options...
Rob Janes Posted January 31, 2011 Author Share Posted January 31, 2011 Indeed, it does drop the FPS quite a bit, but NOT to a point where it drops below the locked 64fps anyways, so it's a moot point from that stand point. You could reduce the number of 'drops' if it was drastically hindering your FPS. Though you are 100% correct, there are MUCH FASTER ways to do this. Link to comment Share on other sites More sharing options...
Robin Posted January 31, 2011 Share Posted January 31, 2011 @SamuGames:> Indeed, it does drop the FPS quite a bit, but NOT to a point where it drops below the locked 64fps anyways, so it's a moot point from that stand point.I suggest you don't dismiss things as a 'moot point' just because they don't have an impact on your performance. That's your machine. Imagine one of your players is getting a much lower FPS. Around 100\. They'll get the exact same performance drop as you, taking them well below the 64 lock.You want to create the game to the lowest denominator, not tailored to your build. Link to comment Share on other sites More sharing options...
Marsh Posted January 31, 2011 Share Posted January 31, 2011 I agree with the fact that it won't make much of a difference currently. Though as robin said if they're is a better method you might as well take it. This method works fine but as I found out making Eclipse++ taking the quick way out does not work. It's fine when it's one feature but eventually you get bogged down with a ton of features that are improperly coded that together really lag the game. Link to comment Share on other sites More sharing options...
Rob Janes Posted January 31, 2011 Author Share Posted January 31, 2011 Noted Robin, and I agree Marsh, however I truly don't imagine people to be running anything less than 1-2GB RAM, with atleast 2Ghz Processor and a 256MB video card. ;) That's what Recommended and Minimum System Requirements listed on the site will be for. No other features at this point really have an impact on the 'rendering engine' so it shouldn't be an issue, though I may end up re-writing this and putting out a new tutorial. I'd be interested to hear what FPS people are getting with this tutorial. Link to comment Share on other sites More sharing options...
Rob Janes Posted January 31, 2011 Author Share Posted January 31, 2011 It wouldn't be difficult to simply change the current code around so it still uses the same Drop Array, and rather than using DrawText it simply Blts the Snow or Rain graphic at the proper screen position. A minor tweak actually. Link to comment Share on other sites More sharing options...
Robin Posted January 31, 2011 Share Posted January 31, 2011 @SamuGames:> It wouldn't be difficult to simply change the current code around so it still uses the same Drop Array, and rather than using DrawText it simply Blts the Snow or Rain graphic at the proper screen position. A minor tweak actually.Hence why I suggested it. ;] Link to comment Share on other sites More sharing options...
Rob Janes Posted January 31, 2011 Author Share Posted January 31, 2011 Very true, I hadn't actually thought it through and realized how simple an update it would be, I'll do this shortly. Thanks for pointing out my blonde moment(s). Link to comment Share on other sites More sharing options...
Robin Posted January 31, 2011 Share Posted January 31, 2011 If you look at my latest post in the Origins thread you'll also see why this would have caused even more unseen problems, like a huge memory leak causing memory usage to escalate horrendously and FPS to slowly drop to nothing. Link to comment Share on other sites More sharing options...
Guest Posted January 31, 2011 Share Posted January 31, 2011 Don't assume players will meet the requirements to play your game. After running Ambardia for 4 years on a dedicated 24/7 server I was still always amazed at how many people still have crappy systems. Also a lot of my players were starting to come from south america and india and almost all of them had less than 1ghz of ram (most in fact were running P2' and 3's with 256 megs of ram. Link to comment Share on other sites More sharing options...
Robin Posted January 31, 2011 Share Posted January 31, 2011 @Ambard:> Don't assume players will meet the requirements to play your game. After running Ambardia for 4 years on a dedicated 24/7 server I was still always amazed at how many people still have crappy systems. Also a lot of my players were starting to come from south america and india and almost all of them had less than 1ghz of ram (most in fact were running P2' and 3's with 256 megs of ram.I'd love to see EE running on that kind of machine. xDEO could probably pull it off. Even more so once I start pre-rendering the maps. Link to comment Share on other sites More sharing options...
Rob Janes Posted January 31, 2011 Author Share Posted January 31, 2011 @Ambard - That's why "Minimum" requirements are posted and support would be limited for people not meeting minimum requirements. True though a lot of people still use slower machines. I've updated the rendering to use images and it only drops FPS by ~20 now. Link to comment Share on other sites More sharing options...
thezeus Posted January 31, 2011 Share Posted January 31, 2011 Very nice, I'll tinker with this when I get home. Did you modify the original post with the change in method? Link to comment Share on other sites More sharing options...
saruish Posted February 11, 2011 Share Posted February 11, 2011 ~~question can we add more then just rain/snow/sun using this? if so I want to add a few more then just the basic's.~~nvm.. I think I know how I can . I will have to add more code then just the ones you have but I can get it working probly.tho I probly can use yours as a base example code.yup I manage to get it working :P tho adding mubital effects is kind of hard and one of the weather effects I want to do consist of that. so any subjestions on how I can do that without it overlaping the other effects also is ~~there a color chart I can follow?~~also I notice on when your changing the color you can type like Red & and yellow to get orange. and stuff like that . I been messing around with it :P now if I can just figure out a way to change one character to another. Link to comment Share on other sites More sharing options...
NightmareX91 Posted February 20, 2011 Share Posted February 20, 2011 How would I do this WITHOUT it drawing the text and lagging the game? So like with sprites. Like eclipse stable/evolution?EDIT: I am having problems doing this. On the client side edits, I have no modFonts! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now