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
roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

quote:

My problem is that I'm absolutely terrible with (OO) design and I usually either
a) Never get started/get lost in the design
b) Start without a design and get stuck somewhere and have to rewrite loads of code
Total rewrites and horrible kludges are actually pretty common. That's not to say it's okay - if you can avoid it, do - but I've come in to several professional team projects where the code was already a tangled disaster area, it's pretty much to be expected in game dev.

A great design is great and all, but at some point you just have to suck it up and work with/around the flaws that turn up in your design as you go. The art is in corectly determining when that point is.

I've found that, for me, the design 'pattern' that works best is to structure everything like a tree - I have a "game" object that contains everything else related to the game contents, and an "engine" object that contains all the DX/whatever functions and object management. Within 'game' I have a 'screen' that contains all the features of a menu screen or game screen (the screen pointer changes to a new object, kind of like you might do with creating a new window in normal Windows programming). Also like Windows I have lists of button objects and such contained within the menu 'windows', almost as if I was reimplementing all of the Windows GUI from scratch.

The reason I say it's like a tree is that you can basically get to *anything* game-data-related from the single 'game' pointer. Ideally you don't want to have to tunnel down like that, it's bad like global variables, but what it means is that when you come to write something later and realise you don't have a good interface for it, and you only want to do it in one little case anyway, you can always bodge out the data you want. Also it means you can pass groups of data to functions, eg. my current project has a 'room' object within 'game', and a list of 'things' within 'room', where 'things' are either players, exits or objects. It makes it easier to write functions that act on stuff within the room, such as a collision detection functions - you can pass the room pointer, rather than the list. And then when you later realise you also want a room map that isn't made up of 'things', like a heightmap or whatever, your collision detection function doesn't have to have its prototype changed to take more parameters.

As I said in the first place, this isn't perfect and tends to make the code a little tanglier than necessary, but it's the balance between the sins of "messy" or "too neat to be usable" that works for me.

Edit: another advantage of this structure is that it makes it relatively easy to back-access stuff from plugin DLLs and the like.

roomforthetuna fucked around with this message at 01:24 on Aug 26, 2010

Adbot
ADBOT LOVES YOU

Unexpected EOF
Dec 8, 2008

I'm a Bro-ny!
Okay, here's a potentially interesting problem.

I'm working on a 2d game that uses a tile engine and makes use of torches to light your way. to match the aesthetic I'm going for, the torches will illuminate a 7 square diameter circle. Now, that's easy enough, it's just some tweaking of the inverse square law. However, the player will also have a lantern he can use that has the same illumination level as the torches but moves with the player. Because of the look I'm going for, I never want the light to be on half of a square but rather the entire square.

Confused? Yeah, it's a bit weird to explain.

Basically what I want to do is take the player's position and then gradually increase the light level on individual squares as the player approaches them and decreases as the player moves away from them. Instead of lighting half a square, I want to take the amount of light that would be hitting the dead center of the square and use that to determine the lighting of the square itself.

My only problem is... uh... how the gently caress do I pull this off?

edit: Right now what I'm planning is to use inverse square from the player position to the middle of the blocks within a certain radius of the player so I'm not checking against every block in the scene like a poorly optimised retard.

Unexpected EOF fucked around with this message at 20:08 on Aug 26, 2010

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!
I'm not really sure what your question is, because it looks like you've already come up with a viable solution!

Unexpected EOF
Dec 8, 2008

I'm a Bro-ny!

Orzo posted:

I'm not really sure what your question is, because it looks like you've already come up with a viable solution!

It's more that I haven't coded for years and I plan to run this on limited (well, iPad/iPhone) hardware so I'm not sure if that's terribly efficient.

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!
If it's tile based and you're really only doing a handful of calculations (one for your lantern and one for each nearby torch) per tile, you should be fine. That's a very, very small amount of processing. Your optimization seems simple and rational as well.

Hughlander
May 11, 2005

Orzo posted:

If it's tile based and you're really only doing a handful of calculations (one for your lantern and one for each nearby torch) per tile, you should be fine. That's a very, very small amount of processing. Your optimization seems simple and rational as well.

Plus being tile based like that I assume there will be a movement animation? So you have the entire movement to calculate the new lights and they won't change until the next movement...

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!
Yeah, but I wouldn't recommend doing that, it introduces complexity when honestly it isn't needed.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
If the lantern is basically just a constant circle of illumination centered on the player, couldn't you precalculate a "mask", representing the light added to tiles? Off the top of my head, I'm imagining something like this:

code:

int RADIUS = 6;
float[][] mask = new float[RADIUS * 2 + 1][RADIUS * 2 + 1];
for(int x = 0; x < RADIUS; x++) {
  for(int y = 0; y < RADIUS; y++) {
    float brightness = RAIDUS - Math.sqrt(x*x + y*y);
    mask[RADIUS + x][RADIUS + y] = brightness;
    mask[RADIUS + x][RADIUS - y] = brightness;
    mask[RADIUS - x][RADIUS + y] = brightness;
    mask[RADIUS - x][RADIUS - y] = brightness;
  }
}

// ...

int playerX; // in tiles
int playerY;

for(int x = 0; x < RADIUS * 2; x++) {
  for(int y = 0; y < RADIUS * 2; y++) {
    int mapTileX = playerX + x - RADIUS;
    int mapTileY = playerY + y - RADIUS;
    float brightness = map.getIllumination(mapTileX, mapTileY) + mask[x][y];
    
    // ...
  } 
}
There may be some errors there (and you'll probably want to scale the brightness value I calculate in my mask), but hopefully it gets the idea across. As Hughlander said, you only have to reapply this when you move to a different tile.

Internet Janitor fucked around with this message at 14:32 on Aug 28, 2010

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Internet Janitor posted:

If the lantern is basically just a constant circle of illumination centered on the player, couldn't you precalculate a "mask", representing the light added to tiles?
I think he was intending the light to fade up as you move across your tile, though that was unclear. Even then, if you wanted to you could precalculate a lookup table of masks.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
Generally in OpenGL can I index materials? I never ran into anything like that when I was manually doing OpenGL stuff awhile back, and messing with Irrlicht it doesn't seem to be obvious either. It looks like I have to go out of my way to change the material whenever I want, which means breaking up processing on something that could otherwise by a huge dump command to the GPU if I could give it all the materials up front.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
roomforthetuna: Sure, or just do a simple tween from whatever the background illumination level is to the sum of the mask and the background.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Internet Janitor posted:

roomforthetuna: Sure, or just do a simple tween from whatever the background illumination level is to the sum of the mask and the background.
No, I mean, even if there is no background illumination, I think he wanted it such that... well, let's say a tile is 32x32, if your lamp is at 15,15 on tile 0,0 then the light on tile 1,0 would be less bright than if you're standing at 29,15 on tile 0,0.

Just a single tile-based lighting mask wouldn't be enough to cope with those 32x32 possible lighting states per tile. But you could do it as a small lookup table of lighting masks.

(All of which is still moot because what he wanted was simple enough that it almost certainly wouldn't be worth precalculating anyway, even if your processor is from 1982.)

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Take another look at my code-
code:
float brightness = RAIDUS - Math.sqrt(x*x + y*y);
The mask I'm generating incorporates the distance of each point from the origin at (RADIUS,RADIUS)- The mask is then laid on top of the player's position to generate a circle around wherever the player might be.

If I was raytracing to take obstacles and shadows into account, it's true that a single lookup table would be insufficient.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Internet Janitor posted:

Take another look at my code-
code:
float brightness = RAIDUS - Math.sqrt(x*x + y*y);
The mask I'm generating incorporates the distance of each point from the origin at (RADIUS,RADIUS)- The mask is then laid on top of the player's position to generate a circle around wherever the player might be.

If I was raytracing to take obstacles and shadows into account, it's true that a single lookup table would be insufficient.
I'm not talking about shadows or anything. Your lighting mask has a resolution of one tile, is what I'm saying, so if you're standing on the left side of the tile you're on, the lighting pattern your mask will make is identical to if you're standing on the right side of the tile, even though in the latter case the light source has moved closer to stuff to the right. If he wants the lighting to change whenever you move (which it would, in his current method), then your method doesn't do that, it only changes whenever you move across a tile boundary.

So I was saying that in order to duplicate the effect he currently has, but using precalculated values, he'd need a lookup table of precalculated masks that chooses an appropriate mask based on the light's position within the tile it's on.

(None of this is true if his movement method resembles Nethack, with no steps smaller than a tile.)

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Ok, I see where you're coming from. I read his description as nethack-style tile-by-tile movement, or at least only calculating lighting to reflect that.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
I am trying to figure out what's going on with the viewing matrix that Irrlicht is using by default with it's absolute transformation (paraphrasing here). I put a camera at 0, 0, 30 looking at (0, 0, 0). I am finding that positive X values move leftwards. The Y and Z components look ok; positive Y moves up, and positive Z approaches the camera. At least I can understand that, but the X side kind of baffles me. How could I transform that matrix to make X move positive to the right? Or is the convention to have it go leftwards?

Mr.Success
Jun 15, 2007

I'm getting closer to completing work on my game and I was wondering what you guys do as far as distributing your projects? Is getting my own hosting the only realistic option?

Simtex
Feb 15, 2008

Mr.Success posted:

I'm getting closer to completing work on my game and I was wondering what you guys do as far as distributing your projects? Is getting my own hosting the only realistic option?

Is it open source? The usual suspects then (sf.net, code.google.com, etc.). If it's closed source you might want to try something like https://www.moddb.com.

You can also try just getting a domain name and pointing it to a service like Google Sites (they brand every page at the bottom though).

Getting your own hosting can be surprisingly cheap and easy though, especially if you're not expecting massive traffic (hopefully your game isn't multiple gigs). Even those stupid "Dreamhost" deals and their imitators (where they claim it's unlimited storage and bandwidth but yank your account the second it starts drawing decent levels of traffic) are workable as long as you're not expecting huge bursts.

Hughlander
May 11, 2005

Anyone remember a website that was a place for people to suggest games that should be written? It went from incredibly detailed to increidbly vague 1 line suggestions?

I think it had a tree navigation like:

Front page:
Simulation
Sports
Puzzle
Action
RPG
Fighting
FPS
Then under FPS:
Team based
Squad based
solo
online only
etc...

Been meaning to poke through things to find something to work on lately...

EDIT: It was on reddit not here that I read it and the site is http://www.halfbakery.com/category/Computer

Hughlander fucked around with this message at 04:48 on Sep 1, 2010

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

Updated my '2D Mac Game Programing' page with rotating sprites and keyboard control. Included code ends up build this program where you can fly a spaceship around the screen using the keyboard.



http://www.isovega.net/macgameprog/index.php?itemid=31

Just started out playing around with SDL and Xcode so I figured I'd see if anyone else was dinking around with it.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
I don't know what to think of what I'm doing here so I thought I'd post here since I think the people on the Irrlicht forums are just confused.

My mind has wandered from doing some kind of tile-based level editor especially since I don't really care about tiles too much and the kind of game I want to do doesn't particularly care about them other than their ability to represent level data.

A decade ago (I freaked out thinking about that) I used to do a lot of Quake 2/Half-Life level editing with Radiant. Irrlicht can slurp up Quake 3 .BSP files so I went bonkers getting GtkRadiant building and made some stuff up.

If you don't know how level editing works in that format, the world geometry is made up of convex surfaces that have to be fully-enclosed. Lights are explicitly given, and then a light map is generated for all the surfaces in post-processing that gives all that eerie shadowing you'd expect.

Of course I neither want a fully-enclosed world nor all that shadowing, so I created two different maps that were enclosed in transparent surfaces, and skipped the lighting step so everything was totally bright. I found I could slurp both into Irrlicht and position next to each other such that they were seamless. I don't know if I'd collide at the transparent boundaries or not, but at least zooming around they could be glued together. My idea was to be able to represent my game world by linking up little sublevels together like this.

Radiant isn't perfect but I know how to use it and I don't have to write a level editor if I go with it, so I thought I could try it. Does this sound completely stupid?

I need to figure out if I can do lighting using Irrlicht after all despite doing no light map post-processing. I assume so but I don't know yet. If it insists on going full bright no matter what lights I decide to use, then... ehhh...

Pfhreak
Jan 30, 2004

Frog Blast The Vent Core!
Are there any actionscript 3 gurus around?

I'm running into a strange issue with my swarms. Right now I can have ~300 boids flying around, and my update call takes 20ms to complete. It's hardly optimized, but that's not really the issue I want to tackle. My update function looks like:

code:
// I cache any calculated distances for a few frames, this method removes stale data
// Takes 0-1ms to run for up to 1000 boids 
ClearBoidDistanceArray();

// Puts boids into a two dimensional array based bucket based on their x y location
// Takes 0-3ms to run for up to 300 boids, grows linearly
Bucketize();

// Constructs a list of nearby neighbors for boids
// Takes 0-3ms for up to 300 boids, grows linearly
GetNeighbors();

// Calculates steering vector for each boid (this is the Cohesion/Separation/Alignment step)
// Takes 0-5ms for 300 boids, grows linearly
GetSteeringVectors();

// Performs updates to velocity/position and other internal behaviors of each boid
// Takes 0-3ms for 300 boids, grows linearly
UpdateBoids();
So that means my update function averages about 10ms for 300 boids. Sure, that's reasonable, workable, and with some clever optimization I could pare that down. Except, about twice a second one of these methods will take 40-90ms to run. It results in a generally smooth movement, interrupted by weird jaggies. It's not consistent to any single method or frame count, and I can't track down where it's coming from. The limited amount of Actionscript knowledge I have suggests it may be the garbage collector doing its thing, but is there any way for me to confirm that? (Any events fired on a collection?) I'm not using the new keyword anywhere within my update function, so I don't think I'm leaving dangling references anywhere.

Second Question: All of my boids use the same appearance (a circle with a line from the center to the edge indicating direction). The constructor for the class looks something like:
code:
public class Boid extends Shape
{
public function Boid(neighborhood:Neighborhood) 
{
	graphics.beginFill(0x00FF00);
	graphics.lineStyle(1, 0x000000);
	graphics.drawCircle(0, 0, boidRadius);
	graphics.moveTo(0, 0);
	graphics.lineTo(boidRadius, 0);
	graphics.endFill();

	///... rest of initialization stuff
}
}
I'm used to working with XNA/SFML where you define an image in one place, and use a lightweight class to splat it multiple times. Am I causing myself overhead by defining the object's "image" for each instance of the image? If so, what's the better model on how to do this?

TL;DR: I suffer from apparently random methods taking 4-10 times as long to run. Could it be the garbage collector? How can I know?
TL;DR2: I define my boid's appearance in every instance of the class, is that wrong? How can I do it better?

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

Your Computer posted:

My problem is that I'm absolutely terrible with (OO) design and I usually either
a) Never get started/get lost in the design
b) Start without a design and get stuck somewhere and have to rewrite loads of code

Honestly I think this happens to everyone. With large projects there's no magic way to design things from the start to ensure that the entire process goes smoothly. The art of it is trying to strike a balance between these two extremes you've described.

Think up a basic plan and go with it. Once you've got something workable, refactor the code until it's nicer. Then move forward, refactoring as needed. Stick to basic OOP principals such as encapsulation as they will make future refactoring easier. A rule of thumb I've been using is to refactor code after I add a new feature. This keeps me interested in the game because I'm making progress, but keeps the code from getting unmanageable.

Try to anticipate what you will need later, but don't go overboard writing classes with no functionality because you'll "need them later." Instead keep the design such that you can add those classes when you need them. This isn't the best example but I'm writing a turn based strategy game that involves units. Obviously there are different types of units, so I would need classes for both the units themselves (location, hitpoints remaining, etc), and the unit types (movement points, models for display, etc). However when first creating the Unit class I didn't make the UnitType class until I already had a basic Unit class functional (I did keep it in mind however). Then I was able to focus my efforts on the UnitType class until that was working. Afterwords I refactored things to tidy them up, then moved on to the next part of the game.

One last thing I would suggest is to avoid the temptation to start again "from scratch" when your code gets ugly. The code may be ugly, but it represents a lot of time and effort that you put into fixing issues that came up. Hundreds of little bugs that you've solved, edge cases that you've worked out. If you start again from scratch you'll likely run into the same issues and have to spend all your time working through them again, only to end up with code that's just as ugly. Better to just refactor the code the best you can, and accept that not all solutions are elegant.

HappyHippo fucked around with this message at 17:03 on Sep 15, 2010

iopred
Aug 14, 2005

Heli Attack!

Pfhreak posted:

TL;DR: I suffer from apparently random methods taking 4-10 times as long to run. Could it be the garbage collector? How can I know?
TL;DR2: I define my boid's appearance in every instance of the class, is that wrong? How can I do it better?

You say you're creating a 2d array every frame, but then that you're suprised that you're GC'ing every few frames. Perhaps instead of recalculating your buckets every frame you should update positions instead, so when a boid moves across boundaries, it removes itself from its bucket and adds itself to its new bucket. That should most definitely be faster.

Secondly, if you're in Flash10 you can do graphics.copyFrom(source) to make a duplicate of your boid sprite from a master Shape/Graphic and just rotate the Sprite/Shape around its origin for rotation.

Pfhreak
Jan 30, 2004

Frog Blast The Vent Core!

iopred posted:

You say you're creating a 2d array every frame, but then that you're suprised that you're GC'ing every few frames. Perhaps instead of recalculating your buckets every frame you should update positions instead, so when a boid moves across boundaries, it removes itself from its bucket and adds itself to its new bucket. That should most definitely be faster.

Secondly, if you're in Flash10 you can do graphics.copyFrom(source) to make a duplicate of your boid sprite from a master Shape/Graphic and just rotate the Sprite/Shape around its origin for rotation.

Sorry, I'm not creating a new 2D array every frame, I'm clearing the contents and placing the boids in the appropriate bucket. No usage of the new keyword here, just adding and removing references to the vectors. It's actually one of the smaller operations in the set, which surprised me. You are right though, I could add a bunch of logic to determine only the boids which had changed buckets and I might get a speed upgrade. I'll have to look into it.

For the second one, that's interesting. I might have to play around with this. Doesn't seem to be a performance enhancer, more of a convenience.

a cyberpunk goose
May 21, 2007

Your Computer posted:

My problem is that I'm absolutely terrible with (OO) design and I usually either
a) Never get started/get lost in the design
b) Start without a design and get stuck somewhere and have to rewrite loads of code

Once you try and fail a few times you'll likely learn how to start structuring things for easy refactoring. Follow Single Responsibility Principle, make things as self contained as is reasonable.

I'm working on a fairly 'robust' project for 1 dude, and the only thing keeping my code sane is how I break things up as I go along, perhaps a screenshot of my file structure will illustrate this. The more you make all these systems able to operate, like a previous poster mentioned, as a tree (ie: you can pick any node on the tree of your project and the rest of that branch should be able to function independently), the better time you'll have changing things as you run into problems. Simply put; isolate things.

Image of my project structure, not entirely useful/informative on it's own but it might give you an idea of how a project can evolve successfully

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

What's a better way to lock my game to a certain frequency other than SDL_Delay()?

It seems like my keypresses are getting dropped if you're in a delay call.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Bob Morales posted:

What's a better way to lock my game to a certain frequency other than SDL_Delay()?

It seems like my keypresses are getting dropped if you're in a delay call.
You probably need to be getting your keypresses a different way. Windows does messages, DirectInput does buffered events, I don't know what SDL offers, but immediate-mode "how's the keyboard right now?" functions are not good for anything that needs to catch short-lived keypresses.

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!
SDL uses an event queue, not a keyboard state poll, so that shouldn't be blocking keystrokes. How are you retrieving input?

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

code:
void mainLoop ()
{
    SDL_Event event;
    int done = 0;
    int direction;
    int draw = 1;
    
    while ( !done ) {
        while ( SDL_PollEvent (&event) ) {
            switch (event.type) 
            {
                case SDL_MOUSEMOTION:
                    break;
                case SDL_MOUSEBUTTONDOWN:
                    break;
                case SDL_KEYDOWN:
                    switch (event.key.keysym.sym)
                {
                    case SDLK_UP:
                        rotatePiece();
                        break;
                    case SDLK_LEFT:
                        direction = BZ_MOVE_LEFT;
                        break;
                    case SDLK_RIGHT:
                        direction = BZ_MOVE_RIGHT;
                        break;
                    case SDLK_DOWN:
                        direction = BZ_MOVE_DOWN;
                        break;
                    default:
                        break;
                }
                    break;
                case SDL_KEYUP:
                    direction = BZ_MOVE_NONE;
                    break;
                case SDL_QUIT:
                    done = 1;
                    break;
                default:
                    break;
            }
        }
        
        movePiece(direction);
        useGravity();
        drawPlayingField();
        drawPill();
        SDL_GL_SwapBuffers ();
        
        // only move the piece down every other time
        draw = -draw;
        if (draw < 0)
        {
            movePiece(BZ_MOVE_DOWN);

            drawPlayingField();
            drawPill();
        }
        
        zapBugs();
        
        SDL_Delay ((11-game.level)*40);
        
        //  if piece is dead, make a new one
        if (current_piece.inPlay == 0)
        {
            createPill();
            current_piece.inPlay = 1;
        }
    }
}
Sorry for the wall of code, should I have used pastebin or something?

I need to re-do my input code because it sucks.

Bob Morales fucked around with this message at 21:39 on Sep 17, 2010

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
Problem I see there - if you pressed "left, left, left, left" within one frame, only one of them would do anything. Or if you pressed "left, left, left, right" you'd come out of the PollEvent loop with just "direction==BZ_MOVE_RIGHT" and all the lefts would be lost. And if you pressed "left" and then unpressed "left" in one frame, you come out with "direction==BZ_MOVE_NONE".

Your treatment of pressing up appears to be alright though.

bgreman
Oct 8, 2005

ASK ME ABOUT STICKING WITH A YEARS-LONG LETS PLAY OF THE MOST COMPLICATED SPACE SIMULATION GAME INVENTED, PLAYING BOTH SIDES, AND SPENDING HOURS GOING ABOVE AND BEYOND TO ENSURE INTERNET STRANGERS ENJOY THEMSELVES
Yeah, do the same thing for the movement options as you do for the rotation. Call another function that moves the piece and pass in the direction as a parameter.

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

roomforthetuna posted:

Problem I see there - if you pressed "left, left, left, left" within one frame, only one of them would do anything. Or if you pressed "left, left, left, right" you'd come out of the PollEvent loop with just "direction==BZ_MOVE_RIGHT" and all the lefts would be lost. And if you pressed "left" and then unpressed "left" in one frame, you come out with "direction==BZ_MOVE_NONE".

Your treatment of pressing up appears to be alright though.

I haven't looked at it in a while, I'm not sure why I split it up to handle 'up' differently. I'll try putting the movepiece() in for left/right/down and see what happens.

That is what's happening, though. You can hit left a bunch of times and nothing happens, or hold it for say 1/10th of a second and nothing happens. So basically I just hold the key down until I'm as far left as I want to be.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Bob Morales posted:

I haven't looked at it in a while, I'm not sure why I split it up to handle 'up' differently.
Probably because you were wanting holding to work on left/right/down, but not for rotating. If you put the movepiece inside the loop then you'll get all the directions working but only if you tap them, unless you also do the 'direction' thing you're doing now. (And if you do it with both without some fiddling you'll have difficulty not moving two squares at once.)

gibbed
Apr 10, 2006

Probably a terrible solution, but why don't you break the poll loop whenever a keydown occurs.

Alex007
Jul 8, 2004

Let's say I want to write an Animal Crossing clone, what game engine/framework would you recommend me ?

Obviously this is just a small project for fun, but this is my first 3D project (or 2.5D in that case, right?) and not having to write the core from scratch would be a nice jumpstart, especially since I wouldn'T know where to start.

The language doesn't matter to me, all I reallt want is a nice game engine/framework with 2.5D support, and if it can support multiplayer (not locally, via a server) it would be awesome. This will be for PC.

Any suggestions ?

PDP-1
Oct 12, 2004

It's a beautiful day in the neighborhood.
XNA supports both 2D and 3D and is free, is based off C#, and runs on PCs. The new 4.0 version was recently released, it is somewhat confusingly packaged as part of the Windows 7 Phone development kit, but you can just ignore the phone stuff and use the Windows Game 4.0 project template to automatically generate a base project with a timing loop and DirectX window and then code your own stuff from there.

They have a 2D tutorial that was written for the 3.0 version, but it should give you an idea of what XNA 4.0 can do. There is some network support but I haven't really messed around with that part much.

Simtex
Feb 15, 2008

Alex007 posted:

Let's say I want to write an Animal Crossing clone, what game engine/framework would you recommend me ?

Obviously this is just a small project for fun, but this is my first 3D project (or 2.5D in that case, right?) and not having to write the core from scratch would be a nice jumpstart, especially since I wouldn'T know where to start.

The language doesn't matter to me, all I reallt want is a nice game engine/framework with 2.5D support, and if it can support multiplayer (not locally, via a server) it would be awesome. This will be for PC.

Any suggestions ?

If you don't mind a proprietary framework I'd give Unity3D a look. For quick development in 3D it's one of the better solutions out there. The free version should have everything you need (though it does add a startup splash screen).

Alex007
Jul 8, 2004

Two really good suggestions guys, many thanks, I'm giving both a try right now.

Took some time to get Unity running but everything is fine now that I found that it requires a DEP exclusion. Runs fine now.

Unity looks like what I was looking for, it really is a game editor (with visual editor) while XNA is more of a game framework (which is fine and gives me more flexibility).

Thanks !

Adbot
ADBOT LOVES YOU

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

I'm having trouble using two different textures in OpenGL (using SDL)
code:
void drawPlayingField(void)
{
	int upperx, uppery, lowerx, lowery; //  our sprite cell corners in pixels
	int col;
	int row;
	
//	glBindTexture(GL_TEXTURE_2D, borderImage);
	drawSprite(0, 0, border);
	
//	glBindTexture(GL_TEXTURE_2D, spriteSheet[0]);	
	//  draw pieces on board
	for (col = 0; col < BZ_PLAYFIELD_COLS; col++)
		for (row = 0; row < BZ_PLAYFIELD_ROWS; row++)
		{
			//  transform cell coords to pixel coords
			lowerx = vborder + (col * BZ_SPRITE_WIDTH);
			upperx = vborder + (col * BZ_SPRITE_WIDTH) + BZ_SPRITE_WIDTH;
			
			lowery = BZ_SCREEN_VRES - (row * BZ_SPRITE_HEIGHT) - BZ_SPRITE_HEIGHT - hborder;
			uppery = BZ_SCREEN_VRES - (row * BZ_SPRITE_HEIGHT) - hborder;
			
			drawSprite(lowerx, lowery, sprite[(((playfield.cell[col][row].color-1)*6)
											   + playfield.cell[col][row].type - 1)]);
		}
}
I commented out the glBindTexture calls so that it works, I just end up getting the same texture used for the border, and the game sprites. drawSprite() just draws a set of GL_QUADS using the currently active texture.

Whichever texture I load last, is the active one. Earlier in the program I have a title screen of sorts, where I load a different picture, draw it right away, and do the whole 'press any key' deal. That works fine. It's just this loop where I can't switch.

If I un-comment the glBindTexture lines, I just get a blank white window. The game still plays, however (I can hear it)


Click here for the full 960x502 image.


Any tips? All the tutorials I have seen online just show:
code:
(pseudo code)
glBindTexture texture
glBegin(GL_QUADS)
....
....
glEnd

glBindTexture texture1
glBegin(GL_QUADS)
....
....
glEnd
(until last texture)
What am I leaving out? The textures are both 512x512 PNG files. I can switch the textures and it does the same thing so I know they are good (random parts of the other texture end up getting used as game sprites)

Update: I threw glGetError()'s everywhere, not getting any (well, I was, but I got rid of them :))

I inserted some glColor() calls in there, to draw the border red, sprites blue, etc, they all draw the right color but they aren't textured. It's as if everything is being drawn in all white, like when you don't have a texture selected. And it only happens when I un-comment the glBindTexture lines (works fine if I just use the texture I loaded last)

Something has to be goofing up the first texture when I load the second. Although, earlier in the game I have a 'title screen' which loads through the same function, and is drawn once. After that I do the function to read the next two files from disk and make textures from them.

Bob Morales fucked around with this message at 17:14 on Sep 21, 2010

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