Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Funking Giblet
Jun 28, 2004

Jiglightful!

The Monarch posted:

Thanks, I'm starting to get the hang of this and even though I sort of new what you're saying here already splitting it up did help. I still don't like the fact that I have to start this whole loop:

code:
foreach (ModelMesh mesh in terrainModel.Meshes) {
   foreach (BasicEffect effect in mesh.Effects) {
for each model (minus the camera and projection stuff) but I guess there's no other way.

If you know there is one mesh you could use
code:
terrainModel.Meshes[0].Effects[0].World = blah;
terrainModel.Meshes[0].draw()
The loop is still better as models can have multiple meshes and effects. Also, you should a world matrix using the position and rotations of the object then assign that to effect.World.

I recommend using the Quaternion class and creating the matrix from that using Matrix.createFromQuaternion(rotationQuaternion);

Adbot
ADBOT LOVES YOU

Ferg
May 6, 2007

Lipstick Apathy

IcePotato posted:

I have to present my independent study (XNA rts game) tommorrow, and I need some help cleaning it up. Anyone going to be around on AIM or IRC later tonight? I'm kind of bad at math things, which is where I need to make it look nice - mostly loop timing stuff.

This is the least productive response ever to your question, but would you be able to put your game up for download somewhere when you're finished? I'd be really interested to see what RTS somebody was able to make in XNA.

Hover
Jun 14, 2003

Your post hits a tree.
The tree is an ent.
The tree is angry.

The Monarch posted:

Thanks, I'm starting to get the hang of this and even though I sort of new what you're saying here already splitting it up did help. I still don't like the fact that I have to start this whole loop:

code:
foreach (ModelMesh mesh in terrainModel.Meshes) {
   foreach (BasicEffect effect in mesh.Effects) {
for each model (minus the camera and projection stuff) but I guess there's no other way.

Well you could just put it in another loop that iterates through a list of models. It's far less ugly and easier to maintain, and would do the same thing. Like:
code:
foreach (Model model in myBigListOfModels) { //the other two loops here }
Otherwise, yeah, what the guy a bit higher up said or the loops. You have to go through every mesh so you have to go through the loops. But you might as well make it nice while you do it.

Hover fucked around with this message at 05:22 on May 1, 2008

IcePotato
Dec 29, 2003

There was nothing to fear
Nothing to fear

Ferg posted:

This is the least productive response ever to your question, but would you be able to put your game up for download somewhere when you're finished? I'd be really interested to see what RTS somebody was able to make in XNA.

Yeah, I'll do that along with my writeup of how NOT to make your first game. It's ... kind of neat. But mostly unfinished, unpolished, and very dumb looking. It'd be awesome if someone ended up extending it though. Not sure if it would be worth the effort, but definitely awesome!
I have to give a presentation on it tomorrow to like the entire department. I think it's going to be 90% powerpoint, and 10% "this is my actual game and what it does" :)

also irc helped me

Ferg
May 6, 2007

Lipstick Apathy

IcePotato posted:

Yeah, I'll do that along with my writeup of how NOT to make your first game. It's ... kind of neat. But mostly unfinished, unpolished, and very dumb looking. It'd be awesome if someone ended up extending it though. Not sure if it would be worth the effort, but definitely awesome!
I have to give a presentation on it tomorrow to like the entire department. I think it's going to be 90% powerpoint, and 10% "this is my actual game and what it does" :)

also irc helped me

During my junior year we spent two semesters planning a developing a project of our choice. Obviously everybody picks a game of some sort because that's more fun. Even after 9 months of work, they all looked unfinished, unpolished, and very dumb. Nothing to worry about there ;)

IcePotato
Dec 29, 2003

There was nothing to fear
Nothing to fear
Okay, last question ever, I swear.
http://pastebin.org/33242
The first unit to move sucks up all the time and moves super-fast. Everyone else moves slowly. I am not sure how to fix this.

The Monarch
Jul 8, 2006

Hover posted:

Well you could just put it in another loop that iterates through a list of models. It's far less ugly and easier to maintain, and would do the same thing. Like:
code:
foreach (Model model in myBigListOfModels) { //the other two loops here }
Otherwise, yeah, what the guy a bit higher up said or the loops. You have to go through every mesh so you have to go through the loops. But you might as well make it nice while you do it.

Yea this is what I'm doing now (a loop that goes through a list of models), I was just wondering if there were any other ways I could break it up or make it cleaner looking.

Lank
Sep 16, 2002

WHERE IS THE CHANCELLOR?!

Hi guys,

I've been trying to get my feet wet with hobbyist game programming for years starting back in like 95 working with QBasic. I would always get stuck on the graphics portion of anything I did because it was always so complex even to just get a graphics device up and running properly. I just started working with XNA a few months ago and I love it. I finally found something I can wrap my head around when it comes to graphics.

Anyway, what I'm currently puzzled over is this. I'm creating a game that's a sandbox type game....but more of a "Set a bunch of settings and then watch what happens...repeat" using Dungeon Crawler-esque needs based AI. Think the Sims but with no user control. The problem I'm having is that I end up having to have each player's character check every other player and object in the game to see if it's close enough to influence its decisions.

I know this is bad. I've already cut down the math by using Vector2.distanceSquared instead of distance but when I get up to 50-60 total players and objects, all checking each other every frame my game slows to a halt. What I'd like to do is some sort of kd-tree or just some simple grid system to only have each character check the objects that could conceivably be within it's area of awareness. Dumb characters can't see / be aware of things at a very far distance, smarter characters can.

Here's my idea, but I wanted to know if this is done more easily some other way.

Split the map into squares with length equal to the maximum distance of awareness for all active characters and have each character only check against characters in adjacent squares on the grid (8 directions). THEN do the distance checking to see if they actually are close enough to be affected by them (attack, run away etc).

I think that will work well enough to make the game not come to a halt but if characters bunch up for any reason, I'm back at square one with n^2 distance checks per frame where n is the number of players and objects.

I've thought of possibly doing only one character update per frame but I think I'd get a faster frame rate at the expense of dumber characters who follow their old target for X frames till it's their turn to be updated again.

Any suggestions?

Star Warrior X
Jul 14, 2004

IcePotato posted:

Okay, last question ever, I swear.
http://pastebin.org/33242
The first unit to move sucks up all the time and moves super-fast. Everyone else moves slowly. I am not sure how to fix this.

http://pastebin.org/33353
Move the copy of the time into the loop, because GameTime is a reference type, which means that you are passing a reference to the time variable in the update function to the move function.
Look up reference types and value types, they are kind of important.

Scaevolus
Apr 16, 2007

Lank posted:

I think that will work well enough to make the game not come to a halt but if characters bunch up for any reason, I'm back at square one with n^2 distance checks per frame where n is the number of players and objects.
It's not the best article, but you're describing Nearest neighbor search.

The better algorithms can reduce the complexity of what you're doing from O(n2) to O(n log n).

IcePotato
Dec 29, 2003

There was nothing to fear
Nothing to fear

Star Warrior X posted:

http://pastebin.org/33353
Move the copy of the time into the loop, because GameTime is a reference type, which means that you are passing a reference to the time variable in the update function to the move function.
Look up reference types and value types, they are kind of important.

oh son of a bitch. I swear to god I've been studying this stuff for three years and this still completely slipped my mind. thanks man.

fret logic
Mar 8, 2005
roffle
Anyone here well versed with GLUT? If so how did you get learned in it? I'm not trying to really make anything serious, just kind of getting my feet wet with graphics programming, and I'm not sure if I should be reading up on GLUT specifically or general OpenGL programming. I'm using C by the way.

Lank
Sep 16, 2002

WHERE IS THE CHANCELLOR?!

Scaevolus posted:

It's not the best article, but you're describing Nearest neighbor search.

The better algorithms can reduce the complexity of what you're doing from O(n2) to O(n log n).

Looking at that article helped a lot. I think I might skip the distance checking and replace it with letting the k closest objects affect the person's actions where k is higher or lower depending on their intelligence / awareness. Then I can impose a hard cap at a value that is just lower than the point I see slow down. So max intelligence = 10 nearest objects / characters processed if I see slowdown at 11 or something like that.

That makes more sense too. Dumber characters would only be able to think about maybe 3-4 of the 20 enemies around them and make judgements based on them where smarter characters could analyze more at once. Just because things are near the person doesn't mean they could handle thinking about all of them. Thanks a ton, that helped a lot. :)

haveblue
Aug 15, 2005



Toilet Rascal

fret logic posted:

Anyone here well versed with GLUT? If so how did you get learned in it? I'm not trying to really make anything serious, just kind of getting my feet wet with graphics programming, and I'm not sure if I should be reading up on GLUT specifically or general OpenGL programming. I'm using C by the way.

GLUT shouldn't take more than a few hours to learn; it's a very simple API that's just designed to get an OpenGL context and some basic input handling up and running in as little time and code as possible. You still use "general OpenGL programming" for drawing.

fret logic
Mar 8, 2005
roffle

HB posted:

GLUT shouldn't take more than a few hours to learn; it's a very simple API that's just designed to get an OpenGL context and some basic input handling up and running in as little time and code as possible. You still use "general OpenGL programming" for drawing.

Ok that makes sense then, just trying to get a handle on GLUT/OpenGL and ncurses before picking which to forge ahead in.

Pfhreak
Jan 30, 2004

Frog Blast The Vent Core!

Lank posted:

I think that will work well enough to make the game not come to a halt but if characters bunch up for any reason, I'm back at square one with n^2 distance checks per frame where n is the number of players and objects.

I've thought of possibly doing only one character update per frame but I think I'd get a faster frame rate at the expense of dumber characters who follow their old target for X frames till it's their turn to be updated again.

Any suggestions?

There have been some good suggestions thus far. (Check out Oct-trees, and other space partitioning.)

But also think about time partitioning. Do you really need to update your AI 60 times a second? If your AI only updated 30, 15, 10, or even 6 times a second, would you really be able to tell? (My guess is no.)

You probably have either a factory or a manager class that is creating or handling these AIs. Basically what you want to do is create a counter in the factory or manager so that you only update each AI every n frames. Try to keep the AIs spread out so that you aren't doing all the updates in one frame.

It's simple, but it will net you a nice boost in frames. It's no substitute for a proper space partitioning algorithm, but it'll buy you a little improvement.

Another way to improve this is to build a system that doesn't rely on the Ai agents to perceive everything, but rather have the sensory inputs tell the AI agents about themselves. Food then tells the agents, "I am food!" and the agents can do what it will with that information. (I'd build a bit field of the possible stimuli, that way you can prevent a lot of lengthy distance calculations by eliminating things the agent can't even respond to.)

Hubis
May 18, 2003

Boy, I wish we had one of those doomsday machines...

fret logic posted:

Anyone here well versed with GLUT? If so how did you get learned in it? I'm not trying to really make anything serious, just kind of getting my feet wet with graphics programming, and I'm not sure if I should be reading up on GLUT specifically or general OpenGL programming. I'm using C by the way.

GLUT's definitely the way to go as far as learning your way around OpenGL and graphics programming are concerned; for building an actual game, you might want to look at a more specialized framework like SDL.

heeen
May 14, 2005

CAT NEVER STOPS
For my project I need a stencil buffer-only write pass, which is the most efficient way to disable writing to the color buffer, glColormask, glBlendfunc or glDrawbuffer?

Lank
Sep 16, 2002

WHERE IS THE CHANCELLOR?!

Pfhreak posted:

There have been some good suggestions thus far. (Check out Oct-trees, and other space partitioning.)

But also think about time partitioning. Do you really need to update your AI 60 times a second? If your AI only updated 30, 15, 10, or even 6 times a second, would you really be able to tell? (My guess is no.)

You probably have either a factory or a manager class that is creating or handling these AIs. Basically what you want to do is create a counter in the factory or manager so that you only update each AI every n frames. Try to keep the AIs spread out so that you aren't doing all the updates in one frame.

It's simple, but it will net you a nice boost in frames. It's no substitute for a proper space partitioning algorithm, but it'll buy you a little improvement.

Another way to improve this is to build a system that doesn't rely on the Ai agents to perceive everything, but rather have the sensory inputs tell the AI agents about themselves. Food then tells the agents, "I am food!" and the agents can do what it will with that information. (I'd build a bit field of the possible stimuli, that way you can prevent a lot of lengthy distance calculations by eliminating things the agent can't even respond to.)

Thanks for the great advice. I've got a few comments on it:

Fewer updates per frame: I had thought about this but didn't really know how to implement it. Would it be as simple as perhaps assigning a 1-10 to each player evenly distributed and then only updated those players labelled with # that frame....so 10 groups would mean each player would only update 6 times per second? Also, does this mean I still update the unit's location / animations / health etc but I don't have him "think" about changing what he's doing? I think I can handle that once I find what I need to about elapsed time in XNA.

Objects holding the info: I read about this style from the very start of this project and I think I'm executing it correctly. I have my objects store their value, their danger, what they can accomplish etc so the agent says "well there's gold to my left and a huge guy with a mace on my right....I'm running towards the gold." The issue I ran into was simply the distance calculations. I needed to know whether the object was allowed to tell the agent what it was and have the agent react or not. But I think I solved that....

It was stupid of me to think that a perfect radius of awareness was necessary. I just made a "cardboard box flattened out" shape around the player with the bounding boxes of the largest square that would fit inside the circle of awareness and the smallest square that would fit on the outside of it. No distance checking, just a few inequalities. I should have thought of it from the beginning but I thought I'd throw it up to show how to save a TON of time and still have an approximate circle of awareness. I'm sure I could add a few more squares to approximate the circle even more but this was a good place to start.

Sorry for rambling.

Only registered members can see post attachments!

Hubis
May 18, 2003

Boy, I wish we had one of those doomsday machines...

heeen posted:

For my project I need a stencil buffer-only write pass, which is the most efficient way to disable writing to the color buffer, glColormask, glBlendfunc or glDrawbuffer?

glDrawBuffer won't do what you want it to do because in that context, 'buffers' are really more like 'surfaces' (Color/Depth/Stencil sets, depending on your dev params). glBlendFunc would be a bad idea since I don't think you'll actually get any sort of savings (i.e. you'll still be paying the full bandwidth cost to be blending a pixel with zero alpha into the buffer) unless you use alpha testing as well, which would kill the entire fragment and mess up your stencil writes. I've always seen glColorMask used to filter out the color buffer in cases like this.

e: "depth testing" => "alpha testing"

Hubis fucked around with this message at 15:11 on May 6, 2008

Sigvatr
Jan 7, 2008

by elpintogrande
If anyone is looking for a game artist, then I can help. I have a portfolio of stuff here: http://sigvatr.com/portfolio/

Email me at me@sigvatr.com if you are interested.

Hubis
May 18, 2003

Boy, I wish we had one of those doomsday machines...

Sigvatr posted:

If anyone is looking for a game artist, then I can help. I have a portfolio of stuff here: http://sigvatr.com/portfolio/

Email me at me@sigvatr.com if you are interested.

Nice stuff; are those screens mock-ups, or from actual games?

Pfhreak
Jan 30, 2004

Frog Blast The Vent Core!

Lank posted:

Thanks for the great advice. I've got a few comments on it:

Fewer updates per frame: I had thought about this but didn't really know how to implement it. Would it be as simple as perhaps assigning a 1-10 to each player evenly distributed and then only updated those players labelled with # that frame....so 10 groups would mean each player would only update 6 times per second? Also, does this mean I still update the unit's location / animations / health etc but I don't have him "think" about changing what he's doing? I think I can handle that once I find what I need to about elapsed time in XNA.
That's exactly it. There's no need to be exactly split into 10 groups, just try to keep it as balanced as possible. Doing it by players could work. The way I set this up for my game was something like this:

Every entity has an Update(GameTime gameTime) function. I update their movements, and their animations, etc, as fast as possible. In that entity there is also an int representing the number of passes before I calculate their 'think' again. When this counter reaches zero, I call Think() and set the counter back to 10. (Use a const for this, so it is easy to change later.)

What I did (because I had no teams in my game) was to create a static variable in my entity called 'offset', which started at 0, and went up to 9. Every time I created an entity, I added the current offset to their first thinking counter. So the first entity would wait 10, then 10, etc, then the second would wait 11 for his first think, then 10 every one after, the third would wait 12, etc... (Does this make sense?) Every frame I also did offset = offset % FRAMES_PER_THINK; This way, offset was always between 0 and 9.

What did you need to know about XNA game time? It's a little confusing, but what you probably want is gametime.ElapsedGameTime.TotalSeconds (I think) that will give you the number of seconds -- full and fractional -- since the last Update().

quote:

Objects holding the info: I read about this style from the very start of this project and I think I'm executing it correctly. I have my objects store their value, their danger, what they can accomplish etc so the agent says "well there's gold to my left and a huge guy with a mace on my right....I'm running towards the gold." The issue I ran into was simply the distance calculations. I needed to know whether the object was allowed to tell the agent what it was and have the agent react or not. But I think I solved that....

Are you familiar with bit fields? Or the [Flags] attribute? I don't know if this is applicable in your game, but say your character responds to food, gold, and enemies, but not beer. You can create an enum that looks like:
code:
[Flags]
public enum ResponseCategory : int
{
  None = 1<< 0,
  Food = 1<< 1, 
  Gold = 1<< 2,
  BadDudes = 1 << 3,
  Brews = 1 << 4,
  Treasure = Gold | Brews,
  All = Food | Gold | BadDudes | Brews
}
This is cool, because every stimulus in your game can have a 'category'. And every dude can have a 'RespondsTo' field.

Then, before you make any expensive distance calculations, you can make a quick check that is basically free on the CPU:
code:
if ((Dude.RespondsTo & Stimulus.Category) == 0)
{
  // Then we can eliminate this stimulus
  continue;
}
Flags have applications ALL over games. They are extremely fast, and in C#, extremely easy to set up and use. You might have to brush up on your bitwise arithmatic a bit. (ha. ha. so punny!)

quote:

It was stupid of me to think that a perfect radius of awareness was necessary. I just made a "cardboard box flattened out" shape around the player with the bounding boxes of the largest square that would fit inside the circle of awareness and the smallest square that would fit on the outside of it. No distance checking, just a few inequalities. I should have thought of it from the beginning but I thought I'd throw it up to show how to save a TON of time and still have an approximate circle of awareness. I'm sure I could add a few more squares to approximate the circle even more but this was a good place to start.

Sorry for rambling.

If you are using the distance squared approach, you are only using a few multiplies and a comparison. It really isn't that expensive. It is usually better to try and eliminate comparisons before any sort of collision algorithm is called.

In the game I'm working on, in addition to the flags, I assign each stimulus a priority. Once I've found at least one stimulus in range, I'll record its priority. Then, I can use that to eliminate distance calculations. If any subsequent stimulus is lower priority than the one I've already found, don't bother checking if it is close or not.

Anyways, I hope that helps you speed some things up. If you have any XNA questions, let me know. I'm no expert, but I've worked with it quite a bit.

IcePotato
Dec 29, 2003

There was nothing to fear
Nothing to fear

Sigvatr posted:

If anyone is looking for a game artist, then I can help. I have a portfolio of stuff here: http://sigvatr.com/portfolio/

Email me at me@sigvatr.com if you are interested.

Ohh, that's nice stuff. And it reminds me - we should do another gamedev competition soon.. Even though my summer is going to be full up with the sweet internship I got. I think I learned my attention span for large-scale independent projects is like exactly 3 weeks.

Lank
Sep 16, 2002

WHERE IS THE CHANCELLOR?!

Pfhreak posted:

great stuff

Wow. That definitely gives me a lot to digest for a while now and tinker with. :) Thanks for taking the time to explain that stuff. I'll definitely check out flags (I've got the big old Oreilly C# bible at home) and play around with them.

Sounds like my slowdown was much more about me updating every frame as opposed to the distance checking I originally thought. I appreciate the help and I'm sure I'll be back when I hit the next road block.

American Psychonauts
Dec 27, 2005

...but inside doesn't matter

Sigvatr posted:

If anyone is looking for a game artist, then I can help. I have a portfolio of stuff here: http://sigvatr.com/portfolio/

Email me at me@sigvatr.com if you are interested.

Your art is good but if you're serious about this I'd take another look at that.
I don't think stuff like clown rape or an ugly school shooting joke site are gonna score you any extra points.

Also put some of your character animations there, those are really important if you want to make games. Now every character is standing in the same pose

American Psychonauts fucked around with this message at 18:09 on May 6, 2008

Pfhreak
Jan 30, 2004

Frog Blast The Vent Core!

Lank posted:

Wow. That definitely gives me a lot to digest for a while now and tinker with. :) Thanks for taking the time to explain that stuff. I'll definitely check out flags (I've got the big old Oreilly C# bible at home) and play around with them.

Sounds like my slowdown was much more about me updating every frame as opposed to the distance checking I originally thought. I appreciate the help and I'm sure I'll be back when I hit the next road block.

Hey, just glad I could help. I wish someone had pointed these things out to me when I had started. (You should see my first pong... Man, what a nightmare.)


Edit:

I'm working on a project and I'm trying to get a handle on pathfinding. The game has a similar view to, say, Black and White. You are far above the terrain, you can place buildings, and there are little mans running all over. That's about all there is to it right now. But the mans are free to run up extreme slopes and through buildings.

My goal: Stop the mans from running through buildings. Be able to paint areas of geometry as impassible. Be able to send the mans to specific points (ie, building entrances) and have them navigate around things like lakes. I'm trying to figure out the best to handle doing this. My first idea was to create a grid of A* nodes across the whole terrain, but the terrain could potentially become very, very large. (I'm using Ogre's Paging Scene Manager.) My next idea was that maybe I could just place the nodes around inaccessable areas. Does that seem like a reasonable approach?

But when I place another building, I'll have to invalidate some edges, add some nodes, and add some edges.

Can anyone point me to some good resources on getting started with this stuff. The book I've got has plenty of resources on how to improve an existing A* implementation. (Heck, I'm not even sure A* is what I want/need!) But it has very little information on actually building the node graph.

Pfhreak fucked around with this message at 16:47 on May 8, 2008

Lank
Sep 16, 2002

WHERE IS THE CHANCELLOR?!

Maybe I can return the favor here.

http://www.policyalmanac.org/games/aStarTutorial.htm

That's the original link I used to get a solid understanding of how the path was actually created using an implementation of the A* algorithm. If that's way beneath what you need, sorry.

As for handling a huge terrain, is there any way you could scale the node size to make waypoints? Like, two passes of the algorithm, one to set direction at a high level to get a target, then at a small level to say actually how to get there. That would keep you from searching a gigantic grid at a very small scale but still have your character moving in the correct direction towards its final destination.


Also, so long as we're ping-ponging each other, is there a perference or best practice between setting up your character array as static vs passing the entire array as a reference to a function? Each character I have has an update / AI method, but it needs to access the other players in the same array. I can see both methods working, but I can also see someone saying OH MY GOD DON'T EVER SET A HUGE ARRAY OF GAME OBJECTS AS STATIC. Not a big deal, just curious.

Pfhreak
Jan 30, 2004

Frog Blast The Vent Core!

Lank posted:

Maybe I can return the favor here.

http://www.policyalmanac.org/games/aStarTutorial.htm

That's the original link I used to get a solid understanding of how the path was actually created using an implementation of the A* algorithm. If that's way beneath what you need, sorry.

As for handling a huge terrain, is there any way you could scale the node size to make waypoints? Like, two passes of the algorithm, one to set direction at a high level to get a target, then at a small level to say actually how to get there. That would keep you from searching a gigantic grid at a very small scale but still have your character moving in the correct direction towards its final destination.


Also, so long as we're ping-ponging each other, is there a perference or best practice between setting up your character array as static vs passing the entire array as a reference to a function? Each character I have has an update / AI method, but it needs to access the other players in the same array. I can see both methods working, but I can also see someone saying OH MY GOD DON'T EVER SET A HUGE ARRAY OF GAME OBJECTS AS STATIC. Not a big deal, just curious.

Just curious, but why does every object need to be able to query every other object? Or rather, why does an object iterate over an array to find the object it needs?

Perhaps you should build some sort of agent/actor/entity manager that maintains Dictionary<string, Dude>. Dictionary (like the STL map) is basically the bestest thing ever. Very fast (think constant time lookups), and wonderfully easy to use. Then, you could implement methods in the manager to get the information you need. Like, lookup by string, lookup by distance, etc. Then you only ever have to store the information once, and never need to pass it anywhere. It provides a common interface among your classes, and reduces coupling.

(Not sure your level here.) Coupling is where classes are reliant on other classes. Let's say you've got DudeA, DudeB, and EnemyA. If DudeA needs to be able to call DudeB.SomeMethod, and EnemyA.OtherMethod, you can't compile without those other objects. And when you change those other objects, bad things might happen to DudeA, he may need rewriting. Coupling leads to spaghetti code.

If you centralize communications between your entities, you always maintain the exact same interface between things. Now, instead of having to make queries all over the place, you have a central repo for your information. Also, you can have your manager class do things like update all the active Agents. It can also be used to ferry information between Agents. Building a messaging system into a centralized class like this makes adding new types of agents a snap, although it requires you have a pretty solid understanding of polymorphism. If you don't know what that means, let me know, it is basically the most important thing you can know.

I'll check out that A* tutorial tonight, see if it helps me out.

Lank
Sep 16, 2002

WHERE IS THE CHANCELLOR?!

I guess query may have been the incorrect word.

I'll make it simple so we don't look like two lovers taking over this entire thread.

I've got my class gameObject. (To answer a later question, yes, I'll be making characters, items, etc off of this base class so I have a basic understanding of polymorphism)

I have an array of players in my main game loop.

For player[1] to use his think method, he needs to know who he should be targetting or where he should be fleeing to. To do that, he needs to know things like player[everything but 1].position, and be able to use things like player[everything but 1].perceivedStrength(). I've never set up a dictionary before but would it make life easier? I just need each player in the array to be able to access all the other players in the same array.

Wouldn't that still be the case if I used a dictionary? I mean, even if I use the dictionary to lookup a target player for the current player to do something to, wouldn't he have to call player[1].attack(player[target])? They need to have access to each other don't they?

Maybe I'm just really not setting up my access correctly. It sounds like I'm the definition of coupling.

Edit: Ok, I just read your first question again. I'm not iterating through an array just to find something, I need to know, for player A, his distance to player B, player B's perceived strength, player B's health, then the same for player C, then D etc for all the other players. The think() method for each player isn't just "Attack closest player" or anything. the whole point of the game is to experiment with a complex AI so each player needs to interact with the others a ton. So I don't understand how a dictionary could hold something like "distance to object X" when that distance is constantly changing for every player to player combination as they move. It's not grib based, it's pixel by pixel movement. Does that clean things up at all?

ps: my email is awmaas@gmail.com if you want to chat more

Lank fucked around with this message at 19:03 on May 9, 2008

Vinlaen
Feb 19, 2008

I'm still trying to create my 2D Worms game and still having trouble... (yes, I'm stupid or something). This was discussed back on page seven but I'd like to bring it back up in case anybody has any new ideas. The suggestions given to me before I didn't quite understand (eg. using a mesh for the 2D terrain deformation, etc)...

Anyways, I'm trying to create a 2D worms game and I'm having some difficulty in figuring out how to store the terrain.

My plan is to create an algorithm that generates terrain by combining several images together to get one final texture. For example, I'll start with the shape of the terrain then fill in mountains, add grass on top, add rivers to the inside, create caves, etc. However, in the end I will just have one very, very large texture.

However, I also plan to allow very large resolutions (eg. 1920x1200 [my 24" monitor's native resolution], 1280x800 [laptop's native resolution], etc), and thus this requires massive amounts of video memory and lots of textures.

For example, if I want to use 1920x1200 (w/32-bit color) and have 6 screens worth of terrain (3 screens wide and 2 screens high), then it will require 55 MB of video memory. Even 1280x800 requires 24 MB of video memory.

The other problem is that typical maximum texture size is only 1024x1024 so I'm guessing I'll need to split my image into many, many smaller textures and then figure out which ones to deform when a collision happens, etc.

Am I approaching this problem wrong? It seems like 1920x1200 * 6 screens just requires a ton of video memory and there is no way around it...

Pfhreak
Jan 30, 2004

Frog Blast The Vent Core!

Vinlaen posted:

I'm still trying to create my 2D Worms game and still having trouble... (yes, I'm stupid or something). This was discussed back on page seven but I'd like to bring it back up in case anybody has any new ideas. The suggestions given to me before I didn't quite understand (eg. using a mesh for the 2D terrain deformation, etc)...

Anyways, I'm trying to create a 2D worms game and I'm having some difficulty in figuring out how to store the terrain.

My plan is to create an algorithm that generates terrain by combining several images together to get one final texture. For example, I'll start with the shape of the terrain then fill in mountains, add grass on top, add rivers to the inside, create caves, etc. However, in the end I will just have one very, very large texture.

However, I also plan to allow very large resolutions (eg. 1920x1200 [my 24" monitor's native resolution], 1280x800 [laptop's native resolution], etc), and thus this requires massive amounts of video memory and lots of textures.

For example, if I want to use 1920x1200 (w/32-bit color) and have 6 screens worth of terrain (3 screens wide and 2 screens high), then it will require 55 MB of video memory. Even 1280x800 requires 24 MB of video memory.

The other problem is that typical maximum texture size is only 1024x1024 so I'm guessing I'll need to split my image into many, many smaller textures and then figure out which ones to deform when a collision happens, etc.

Am I approaching this problem wrong? It seems like 1920x1200 * 6 screens just requires a ton of video memory and there is no way around it...

I'm going to take a stab in the dark here, because I'm not sure if this solution would work, buuuut, couldn't you build a big 2 dimensional array, 1920x1200, and store bits in it? 1 for visible/collideable and 0 for not? Then, you can break up your giant level texture into smaller pieces, and use the bit field to determine whether that section of the level should be drawn?

Also, you could only send the visible pieces of the large texture to the video card. Keep them loaded and ready to go, but only draw them when they are in the frustrum of the player's camera.

quote:

Ok, I just read your first question again. I'm not iterating through an array just to find something, I need to know, for player A, his distance to player B, player B's perceived strength, player B's health, then the same for player C, then D etc for all the other players. The think() method for each player isn't just "Attack closest player" or anything. the whole point of the game is to experiment with a complex AI so each player needs to interact with the others a ton.

Ah, I see now. Your player will respond to whatever has the highest priority, where priority is some value derived from a complex function that considers things like distance, enemy health, enemy strength, player's current status, etc?

In that case, you'll just need a List<> and a foreach(Player curPlayer in PlayerList). You'll have to go through each one, and try to use inexpensive eliminations before expensive ones. (Check things like, "Are we on the same team?" first, and "How far away are you?" later. But I think you already knew that.)

Tinyn
Jan 10, 2003

Ive been thinking about writing a class to abstract whether or not the OpenGL program is using VBOs or VBAs from the rest of the program. But theres issues about who has to handle the memory when its VBAs, Interleaved or not interleaved, offsets when interleaved, stuff like that. Anyone have any ideas how they'd go about that?

Vinlaen
Feb 19, 2008

Pfhreak posted:

I'm going to take a stab in the dark here, because I'm not sure if this solution would work, buuuut, couldn't you build a big 2 dimensional array, 1920x1200, and store bits in it? 1 for visible/collideable and 0 for not? Then, you can break up your giant level texture into smaller pieces, and use the bit field to determine whether that section of the level should be drawn?
Yeah, I was thinking about that. Actually I'd use a static resolution-independent texture size (eg. array) that just contains 1 or 0 (for solid or not solid).

Pfhreak posted:

Also, you could only send the visible pieces of the large texture to the video card. Keep them loaded and ready to go, but only draw them when they are in the frustrum of the player's camera.
You're saying to create my huge (1920x1200x32x6) textures in system memory and then copy only a display resolutions worth of data to the video card? I've thought about this too and think it might be my only option but I'm hoping for an easier/faster solution.

Thanks a ton for the help though!

Seabert
Apr 13, 2008
Hi guys,

I've been working on a shader to place on a heightmap, which I'm now 'porting' from RenderMonkey to my project in MDX9/C#.
This is what I've got in my PS (2.0), and this worked just fine in RenderMonkey:
code:
texture tex1;
texture tex2;
texture tex3;

sampler2D Texture2 : TEXUNIT0 = sampler_state { texture = <tex2>; magfilter = LINEAR; 
minfilter = LINEAR; mipfilter=LINEAR;  AddressU = mirror;  AddressV = mirror;};
sampler2D Texture1 : TEXUNIT1 = sampler_state { texture = <tex1>; magfilter = LINEAR; 
minfilter = LINEAR; mipfilter=LINEAR;  AddressU = mirror;  AddressV = mirror;};
sampler2D Texture3 : TEXUNIT2 = sampler_state { texture = <tex3>; magfilter = LINEAR; 
minfilter = LINEAR; mipfilter=LINEAR; AddressU = mirror; AddressV = mirror;};
code:
float4 ps_main(VS_OUTPUT Input) : COLOR0
{
 float4 texColor = float4(0.0, 0.0, 0.0, 1.0);
 texColor += (tex2D(Texture1, Input.TexCoords.xy) * Input.TextureWeights.x);
 texColor += (tex2D(Texture3, Input.TexCoords.xy) * Input.TextureWeights.y);    
 texColor += (tex2D(Texture2, Input.TexCoords.xy) * Input.TextureWeights.z);
 return texColor; 
}
Now it seems that there's always 1 texture that doesnt show. It also seems that the order in which I define my sampler2D's matters here. The first sampler2D is the one that doesnt appear. This is what happens when I define them in a different order: (its a spinning sphere btw so the appearing order is correct)


Is there some sort of limit on these sampler objects? According to Wikipedia there isn't a maximum, and compiling in 3.0 doesn't seem to fix it.

Does anyone have any experience with this? Thanks a bunch in advance :)

tyrelhill
Jul 30, 2006
Looks fine to me, my guess is you're not passing the texture to the gpu somewhere for Texture1.

Seabert
Apr 13, 2008

tyrelhill posted:

Looks fine to me, my guess is you're not passing the texture to the gpu somewhere for Texture1.

As far as I know it's passed correctly. The only difference between those 2 screenshots is the order in which I declared the samplers, and there are 3 different textures total (grass, sand, rock), so I don't think thats it. Maybe it's my method of passing the information? This is what I've got:
code:
/* textures */
m_effect.SetValue("tex1", m_grass);
m_effect.SetValue("tex2", m_rock);
m_effect.SetValue("tex3", m_sand);
EDIT: Someone from Gamedev suggested to add a register() and it worked like a charm :)

code:
sampler2D Texture1 :register(s1) ...
sampler2D Texture3 :register(s3) ...
sampler2D Texture2 :register(s2) ...

Seabert fucked around with this message at 17:30 on May 12, 2008

tyrelhill
Jul 30, 2006
I'm starting some research for a project I start in a few months and want to ask a few questions here about some good sources.

First, I'm looking for any and all game development based design pattern papers and books. I've found a good amount of stuff already, but was wondering what anyone else around here happened to know about.

Second, I'm going to need to implement gameswf (http://www.tulrich.com/geekstuff/gameswf.html). Does anyone know of any similar projects that are more up to date (and open source)?

heeen
May 14, 2005

CAT NEVER STOPS
I'm trying to use glClipPlane here, but no matter what values I send, it doesn't clip anything. If I try a positive and a negative halfspace surely some clipping should be noticable?

Adbot
ADBOT LOVES YOU

haveblue
Aug 15, 2005



Toilet Rascal

heeen posted:

I'm trying to use glClipPlane here, but no matter what values I send, it doesn't clip anything. If I try a positive and a negative halfspace surely some clipping should be noticable?

glEnable(GL_CLIP_PLANE0);

Also remember that clip planes use eye coordinates.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply