<- 1  -   of 3455 ->
^^
vv
List results:
Search options:
Use \ before commas in usernames
yeah my code uses the event struct
I'll see if I can clean it up a bit and show you, it's a mess the way it is now
awesome. I'd love to see that (even if its messy)
ok I'll see what I can do
thanks!
well that avatar was unfortunate
Edit history:
DJGrenola: 2017-08-23 11:14:08 am
DJGrenola: 2017-08-23 11:13:40 am
DJGrenola: 2017-08-23 11:12:45 am
DJGrenola: 2017-08-23 11:12:25 am
DJGrenola: 2017-08-23 10:44:56 am
Code:
#include <stdio.h>

#ifdef WIN32
#include "windows.h"
#include "SDL.h"
#else
#include <unistd.h>
#include "SDL2/SDL.h"
#include "SDL2/SDL_joystick.h"
#endif 

#define EVENT_POLL_MAX 100  // only process maximum of 100 events per loop

int main(void) {

  SDL_Event e;
  int num_events;
  
  // wastes 64K of memory but keeps track of pretty much any Unicode character you might find on a keyboard
  char key_states[65535];
  SDL_Window *w;

  // should check errors here
  SDL_InitSubSystem (SDL_INIT_JOYSTICK | SDL_INIT_VIDEO);
  SDL_JoystickEventState(SDL_ENABLE);
  
  // wipe the key_states array
  memset(key_states, 0, 65535);
  
  w = SDL_CreateWindow("Bismarck biss Mark, bis Mark Bismarck biss.",
                       SDL_WINDOWPOS_UNDEFINED,
                       SDL_WINDOWPOS_UNDEFINED,
                       300, 300, SDL_WINDOW_RESIZABLE);
                       
  SDL_RaiseWindow(w);
  SDL_ShowWindow(w);

  while (1) {
    
    num_events = 0;
    
    while (SDL_PollEvent(&e) && (num_events<EVENT_POLL_MAX)) {
      
      int my_key;
      
      switch (e.type) {
        case SDL_QUIT:
          printf ("\nSDL_QUIT\n");
          exit(0);
        case SDL_KEYDOWN:
          num_events++;
          my_key = e.key.keysym.sym & 0xffff; // make sure key value can't exceed 65535
          key_states[my_key] = 1; // game logic can check key_states array to see what is currently pressed
          break;
        case SDL_KEYUP:
          num_events++;
          my_key = e.key.keysym.sym & 0xffff; // make sure key value can't exceed 65535
          key_states[my_key] = 0; // game logic can check key_states array to see what is currently pressed
          break;
      }
      
    }
    
    // constantly print out the state of the 'a' key:
    printf("key_states['a'] = %i\n", key_states['a']);
    
#ifdef WIN32
  Sleep(100);
#else
  usleep(100000);
#endif
    
  }

  SDL_Quit();
  
  return 0;
  
}


this is kind of what I'm doing -- I've tested it on Linux, it ought to work on Windows but I haven't tried it.

it uses a big array key_states to keep track of which keys are pressed, then the game logic can just check key_states to find out what's currently pressed and what isn't
my actual event code is a lot more complicated because it's fully remappable, supports multiple players and basically any device you can throw at it

it also doesn't work properly :/
Edit history:
ryu: 2017-08-23 03:25:23 pm
thanks for sharing!
Code:
#define EVENT_POLL_MAX 100  // only process maximum of 100 events per loop

heh, that's clever. did you throw that in as a wild guess, do rigorous testing or even learn how exactly the evnt loop works? first time I got suspicious was when I realized putting processing into that loop would (or should) mean holding a button down halts the whole game loop. I did a test doing exactly that, with a call to SDL_delay() outside the event loop. the delay actually happened every 40 runs, so it seems there's a limit coded in there already.

Code:
SDL_JoystickEventState(SDL_ENABLE);

was the gamcontroller feature a thing in the version of SDL you used? supposedly that does wonders to pad compatibility (assuming that isn't part of your full code since you mention good compatibility in that)

Code:
Bismarck biss Mark, bis Mark Bismarck biss.

rotfl

Your switch is interesting. Here's my test thing that doesn't work:
Code:
while(
        SDL_PollEvent(&sdl_event) != 0) {
        
        if (sdl_event.type == SDL_KEYDOWN) {
            if (sdl_event.key.keysym.sym == SDLK_UP) {
                up++; 
            } else {
                up = 0;
            }
            if (sdl_event.key.keysym.sym == SDLK_RIGHT) {
                right++; 
            } else {
                right = 0;
            }
            if (sdl_event.key.keysym.sym == SDLK_ESCAPE) {
                quit = 1;
            }

            SDL_WaitEvent(&sdl_event);
        }
        }
        if (sdl_event.type == SDL_QUIT) {
            quit = 1;
        }

Comparing it to yours, the problem with my code must be that switching the keyboard button prevents the loop from checking the other cases. problem is I'm not even using a switch here trying to solve that lol

here's the other thing I tried, which probably does the same as your code. i'm not sure about future remappability (should be possible though).
Code:
        
SDL_PollEvent(&sdl_event);
        if (sdl_event.type == SDL_QUIT) {
            quit = 1;
        }

        if (key_state[SDL_SCANCODE_RIGHT] && key_state[SDL_SCANCODE_UP]) {
            printf("pressing RIGHT-UP\n");
        } else if (key_state[SDL_SCANCODE_LEFT]) {
            printf("pressing-left\n");
        } else {
            printf("not pressing right-up...\n");
        }
        if (key_state[SDL_SCANCODE_ESCAPE]) {
            quit = 1;
        }
Code:
#ifdef WIN32
  Sleep(100);
#else
  usleep(100000);
#endif

I read that SDL_Delay is unreliable and leads to unstable FPS. Does your solution circumwent that?
Code:
        if (pad) {
            printf("pressing up? %i\n", SDL_GameControllerGetButton(pad, SDL_CONTROLLER_BUTTON_DPAD_UP));
            printf("pressing A? %i\n", SDL_GameControllerGetButton(pad, SDL_CONTROLLER_BUTTON_A));
        } else {
            printf("no pad found :(\n");
        }

works too. no reason to use the event loop unless I'm missing something. next is putting it all in an array like you did, let's see how that goes with my method...
here's my full code btw

https://git.hirasaka.io/gitbucket/ryu/sdl_game/blob/master/main.c
red chamber dream
http://www.bbc.com/news/business-41021783

this is interesting because google + walmart might just be able to take on amazon
is voice shopping really that big? it's the first time I'm hearing about it, and I can't see myself ever using such a service
like hell i'll purchase physical goods without having a look at at least a picture or comparing articles
red chamber dream
i think people mostly use it to reorder stuff, or order commodities
Edit history:
ryu: 2017-08-24 03:49:16 pm
guess it makes sense if there's something you order over and over. used to be refill cartridges for my ink pen for me until I switched to a converter and ink bottle
sorry ryu I'll get back to you on this, I've had a long day and I'm exhausted
red chamber dream
my idea for a tshirt

BAN F**CKING

with a picture of a fracking machine that looks like a dick fucking a vagina
red chamber dream
i'm drunk, you're welcome
Quote from DJGrenola:
sorry ryu I'll get back to you on this, I've had a long day and I'm exhausted

no problem. I'm in no hurry here.

lol ark...
Quote from DJGrenola:
aw yeah, just ordered these shiny beauties for my guitar amplifier so I have spares for the gig next month

I have such a fetish for valves / tubes


go back to tourian
because of tubes?
red chamber dream
lol metroid was the first thing that came to mind for me too