Need to access global variables for MMORPG

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

Kicksome
Posts: 52
Joined: 01 Sep 2007, 02:25
Contact:

Need to access global variables for MMORPG

Postby Kicksome » 28 Nov 2007, 19:44

I have a MMORPG that loads 1000's of players into memory. It's broken up into 100 different maps - which are each rooms with their own extension to control movement of players and monsters. Each map might have 50 monsters in a monster={} struct.

People walk around on various maps. Each map has their own set of monsters and other players on them which update the flash map.

When they walk into a monster it puts the player into combat (different flash app and different room with combat extension) - they battle and it works great. Once the are done it puts them back on the map.

The problem is - I need to update the "map" room with the results of the battle. I need to tell the previous room that monster xxx is dead so it will no longer show on the map. And I need to do it from the server e.g. prevRoom().monster[12324].alive=0

How can I do that without writing to the database and then reloading everything?
Menser
Posts: 111
Joined: 13 Nov 2007, 18:32

Postby Menser » 29 Nov 2007, 01:16

Heya-

Sucks doesnt it? I ran into the same problem where i wanted various extensions to talk to each other. Guess what, its a no no pretty much.

While the separation of everything into different extensions seems logical,
it is actually less efficient when using smart fox. Why?

1) Extensions cant talk to each other to easily, or well.
2) The setup of smart fox creates the interesting problem of the time old thread race if two different extensions (and even some functions in a single extension if i remember correctly) are trying to access the same variables. This can be avoided if you use java, Lapo makes mention of this in a post somewhere.

What should you do?

Well, it seems the right answer, at least when using smart fox, is to put everything into a single extension. Once again, this doesnt have to be the case if you are using java to write your extensions.

So instead of controlling everything on a 1 extension per room basis, have one zone extension control everything for the entire game. If written properly, this would actually be more efficient and safer(in terms of thread races) when using smart fox.

Why?
Well if most of your code is the same, for each room you are loading a separate copy of that code. In most situations i would imagine you have alot of duplicate code in your extensions. So this takes more memory to load all this. Plus it creates more threads that run at once, since each extensions gets its own thread(or more). which in turn means each thread gets less time. Which if you have some processor intensive functions running, would mean you have more of them running at once, which could slow things down .

By putting it into a single extension you avoid alot of the problems above.

Now i could be wrong on some of this, since i myself am fairly new to Smart Fox server, so if someone more knowledgeable would chime in that would be cool.


Also if you REALLY need to separate extensions to talk to each other, you can make use of room or user variables to pass data between the two.

I haven't done this myself, i have just went the route of everything in one extensions, but this is what i was thinking.

Basically you have to know what you everything that can possibly be set to this variable. Why?

Cause this variable will basically just represent different states. Since the extensions run in separate threads, and you don't want one extension playing with the variable while the other is.

In each extension you first check what data is in the variable. If the variable has the value matching the extension, you have that extension do something, then update the variable. This way each extension is only reacting and modifying the variable when it needs to, and they wont mess with each other. As i said, you have to know what you will be setting it to ahead of time as each extension will have to have code in it telling it what to do when the room variable matches certain criteria.

Does that make sense?



Questions, Comments, Corrections?
Menser
Kicksome
Posts: 52
Joined: 01 Sep 2007, 02:25
Contact:

Postby Kicksome » 29 Nov 2007, 01:59

Thanks for the response. I figured as much. I'm re-writing my code to put it all in one extension. I'm just not up for messing with Java at this point. It looks like I'm making some progress - I guess I'll let you know soon. Thanks again for the help. Seems like a lot of looping to figure out who to send requests to - but I guess that's what has to be done.
Menser
Posts: 111
Joined: 13 Nov 2007, 18:32

Postby Menser » 29 Nov 2007, 03:20

Heya-

If you do it properly, you shouldn't have to loop through anymore people then you do already. You still make use of rooms. and you can access the rooms (And all its properties such as players) from the zone level. So you can send messages to specific rooms where only certain groups of people are.

If you have any more questions, just ask.

_-Menser-_
Kicksome
Posts: 52
Joined: 01 Sep 2007, 02:25
Contact:

Postby Kicksome » 29 Nov 2007, 16:50

Right now I've decided to just put everything in one room.

So basically I load all the maps into a structure, and monsters into a structure when the extension starts.

When a player logs in the are added to the player structure

I run a set interval every 500ms that:

1) loop through the players/monster structure 1 time and create a data array for each map with the current player/monster location's and status.
This ends up creating an array data structure for every map

2) loop through the active players and send them the appropriate map data structure (depending on their map) - which the flash client then processes.

I'm a little concerned because right now it's taking 3% CPU time (4 core, 4 gig machine).
1) If I make 5x more monsters and maps than I have right now that might take 15% - 20% cpu time just to process the loop (probably).

2) Right now I'm sending the data to only 2 people. I'll need to send it to at least 500 - 1000 users. I'm not sure how much more overhead it'll take to send the data to more people.

3) 500 - 1000 users sending their movements to the server - not sure how much processing that will take. (although all it does is update a x,y,map position)

So far though - the performance for combat has been excellent. We have 100's of combat rooms that dynamically get created and it takes very little CPU time.
Menser
Posts: 111
Joined: 13 Nov 2007, 18:32

Postby Menser » 29 Nov 2007, 22:18

Heya-

You dont need to compress everythin down to a single room, you just have to have all your code in a single zone extension. You can still use multiple rooms.



For instance, You have room 1, which correlates to map 1.

You have your zone extension load the map, and push it off into a room variable for Room 1.

When Player A (who we say is in map 1) loads, you put him in the appropriate room(would do same for NPCs, etc).

Now say you want to send something to only players on map 1, you would simply get the reference to the room(which correlates to a map), which contains a reference to all the players contained in the room.

You would also use room variables to store the NPC/Creatures and items that are in the map. This way everything is still segmented, and limits the number of things you search through when trying to find things.

With me?

Hit me back with any questions, or if you have AIM, i can be reached at CyphonWork.

_-Menser-_
Kicksome
Posts: 52
Joined: 01 Sep 2007, 02:25
Contact:

Postby Kicksome » 06 Dec 2007, 05:02

Don't room variables get sent to all the players in a room? I have pretty big player objects with tons of stats that users don't need have sent to them since it's done on the server side.
patso
Posts: 380
Joined: 13 Nov 2006, 13:44
Location: Sofia, Bulgaria

Postby patso » 06 Dec 2007, 06:22

Kicksome wrote:Don't room variables get sent to all the players in a room? I have pretty big player objects with tons of stats that users don't need have sent to them since it's done on the server side.


You can use room properties instead - they are not sent to the clients.
Kicksome
Posts: 52
Joined: 01 Sep 2007, 02:25
Contact:

Postby Kicksome » 06 Dec 2007, 13:16

I'm curious - if I have something like:

Code: Select all

monsters={}

for (i=0; i< 1000; i++) {
monsters[i] = {}
monsters[i].id = i
monsters[i].name = "monster " + i
etc....
}

room = createroom(room, null)
room.properties.put("monsters", monsters)


Does this put just a pointer to monsters??? Or does it copy all the acutal values to the room?

So if I alter the monsters object in one room will it alter it in the other?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 07 Dec 2007, 08:25

Of course it is a reference (not a pointer)
In Object Oriented languages objects are always passed as a reference and not copied (except for structs in C/C++/C#, but this is not the case.)
Lapo
--
gotoAndPlay()
...addicted to flash games
darkxer878
Posts: 2
Joined: 19 Jul 2010, 17:46

Postby darkxer878 » 19 Jul 2010, 19:08

Kicksome wrote:I'm curious - if I have something like:

Code: Select all

monsters={}

for (i=0; i< 1000; i++) {
monsters[i] = {}
monsters[i].id = i
monsters[i].name = "monster " + i
etc....
}

room = createroom(room, null)
room.properties.put("monsters", monsters)


Does this put just a pointer to monsters??? Or does it copy all the acutal values to the room?

So if I alter the monsters object in one room will it alter it in the other?


What was the answer to this question anyways?

I'm guessing Room extensions can access references to other room variables / properties, allowing room extensions to share data?

Is there an example of this somewhere?

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 21 guests