• Content count

  • Joined

  • Last visited

Community Reputation

135 Neutral

About Chr1sen

  • Rank
  1. Direct3D UYVY texture.

    Thanks. I got everything working now. It's a shame that I really didn't see people use the "Pitch" property. I guess they are mostly dealing textures that have the Pitch same as Source width.   /// <summary> /// Copies content into destinationBuffer. /// </summary> /// <param name="texture">actual texture </param> /// <param name="contentToCopy">source bfufer</param> /// <param name="sourcePitch">source stride</param> private static void CopyToTexture(Texture texture, byte[] contentToCopy, int sourcePitch) { var data = texture.LockRectangle(0, LockFlags.Discard); var y = 0; for (var scanLineStart = 0; scanLineStart < contentToCopy.Length; scanLineStart += sourcePitch, y++) { data.Data.WriteRange(contentToCopy, scanLineStart, sourcePitch); data.Data.Seek((y + 1)*data.Pitch, SeekOrigin.Begin); } texture.UnlockRectangle(0); }   And if anyone is interested, then I ended up using this for my YUV->RGB shader: though I am thinking about writing my own shader that could use only one sampler2D, so I could pass packed YUV formats directly into the GPU. Though I am not sure where to begin. Is that even a good idea? The texture is defintely gonna be huge as hell though.
  2. Hello! I am making custom video player that can play videos using UYVY textures. Now I've made sure two things(fairly new GPU card): 1) my computer supports nonpower textures 2) my computer supports UYVY textures 3) the data and width/height is correct(frame). I've verified it with many different ways. For example, doing the conversion manually into RGB32 and using that as texture, it works. Bottom line is; my GPU can't handle UYVY textures sometimes. For example, some video resolutions work fine, such as: 1024x720 720x528 or something.. On other video resolutions, the texture output is completely gibberish. It's just a bunch of messy stuff and reminds me zigzag lines. Are there some limitations I am not aware of? Or has anyone dealt with this? On another note, I am using Direct3D9, can anyone suggest me some keywords to google around so I could upload YUV data into shader and then take over the "sampling" process & converting it into RGB process? As far I've searched; you can have only one texture active at shader stage, with DX9, so it means I have to upload all the YUV data into texture at once. So, for example UYVY frame will take width*height + width*height/2 + width*height/2 pixels, and I am not sure if GPUS even support so big textures ?! when talking about fullHD movies. I am also not sure how should I do the sampling myself.
  3. So I was working on my game.. it seems that my game seems to just stop at some random times and skips rendering new frame where player moves, so it kind of seems like player has teleported.. Im not exactly sure what the problem is, is it the rendering part of maybe it is skipping the logic part.. either way it seems that something weird is going on. Game loop public void run() { sync.start(); int last_time = 0; int frames_done = 0; Field f = game.getField(); boolean bomb_planted = false; // we can only plant bombs when we press button not hold it down. while(running) { /* while(sync.tick == 0){ try{Thread.sleep(100 / 50); } catch(Exception e){} }*/ while(sync.tick &gt; 0) { int old_ticks = sync.tick; // Check out various keys lol if(keystate[SPACE_BAR]){ if(!bomb_planted){ // Send packet to server indicating that we want to plant bomb. player.write(Gp.genPack(Gp.PLANT_BOMB, new String[]{Integer.toString(player.getId()), player.getHash(), Integer.toString(player.getX()), Integer.toString(player.getY())})); bomb_planted = true; } } else{ bomb_planted = false; } // Update player positions // dead reckoning Player a[] = game.getPlayerlist(); for(int i = 0; i &lt; a.length; i++) { if(a[i] != null && a[i].getMoving()) { int x = a[i].getX(), y = a[i].getY(); int key = a[i].model.getDir(); if(key == 0){ x += foffset; } else if(key == 1){ x -= foffset; } else if(key == 2){ y -= foffset;} else if(key == 3){ y+= foffset;} a[i].moveTo(x, y); } } boolean mv = false; for(int i = 0; i &lt; keys; i++) { if(keystate[i]) { mv = true; int key = i; if(player.model.getDir() != key || !player.getMoving()) { player.write(Gp.genPack(Gp.CLIENT_GONNAMOVE, new String[]{Integer.toString(player.getId()), player.getHash(), Integer.toString(key), Integer.toString(player.getX() + 50), Integer.toString(player.getY())})); System.out.println("DROLL"); } break; } } // Update bombs // Each logic frame is fixd at specific rate, our example is 40! // So it means that the bomb animation should change.. boolean fbomb = true; /* synchronized(bombs) { ListIterator&lt;Bomb&gt; itr = bombs.listIterator(); while(itr.hasNext() && fbomb){ Bomb b =; b.counter += 1; b.nextAnimation(); if(!b.alive) { itr.remove(); } } }*/ sync.tick -= 1; if(old_ticks &lt;= sync.tick) break; // abort logic, we need to draw! // End of Game logic loop } if(sync.fgbk &gt;= 10){ // Seconds has passed f.setFps(frames_done); sync.fgbk = 0; frames_done = 0; } // We have time to draw now. game.triggerUpdate(); frames_done += 1; } } Here is the triggerUpdate() public void draw() { Graphics graphics = null; try { graphics = buffer.getDrawGraphics(); Graphics2D gx = (Graphics2D)image.createGraphics(); gx.setColor(; gx.fillRect(0, 0, width, height); // Draw bombs /* synchronized(bombs) { ListIterator&lt;Bomb&gt; itr = bombs.listIterator(); while(itr.hasNext()){ Bomb b =; drawBomb(gx, b); } }*/ if(player_list != null) { for(int i = 0; i &lt; player_list.length; i++) { if(player_list[i] != null) { drawPlayer(gx, player_list[i]); /* gx.drawString("["+i+"]PlayerX" + player_list[i].getX() + " PlayerY" + player_list[i].getY(), 200, 75 + i * 10);*/ } } } graphics = buffer.getDrawGraphics(); graphics.drawImage(image, 0, 0, null ); if( !buffer.contentsLost() ); } finally { // if( graphics != null ) // graphics.dispose(); } } and here is the timing class I use(sync) package Client; import java.util.Calendar; import java.util.Timer; import java.util.TimerTask; // A class to lock our game logic FPS :-) // too bad I couldnt find one in Java. public class Synchronization { public static int FPS = 50; // We do 40 logic updates per second. // What that means is that we increment our 'tick' variable each 1000/FPS ms. public int tick = 0; public int fgbk = 0; private int cwreal = 0; private Timer timer; // timer for synchronization logic private Timer fpstimer; // we use it to get fps class RemindTask extends TimerTask { private Synchronization g; public RemindTask(Synchronization g) { this.g = g; } public void run() { tick += 1; cwreal += 1; if(cwreal == FPS){ tick = 1; cwreal = 0; } } } class FPSTask extends TimerTask { private Synchronization g; public FPSTask(Synchronization g) { this.g = g; } public void run() { fgbk += 1; } } public void start() { timer = new Timer(); timer.scheduleAtFixedRate(new RemindTask(this), Calendar.getInstance().getTime(), 1000 / FPS); fpstimer = new Timer(); fpstimer.scheduleAtFixedRate(new FPSTask(this), Calendar.getInstance().getTime(), 100); // Every 100 ms } public void stop() { timer.cancel(); } } I hope anybody can take look and has any ideas. Ive also attached project's source because Im desparetly in need of help :P, this seems to be happening on other computers too and switching timer technology doesnt seem to do any good. takes care of screen takes care of player movement and updating it's position
  4. hey everybody. im building my first 2d network game. im already facing a problem.. public void run() { // We are now dealing here // with reading from socket and writing there // we understand protocol etc.. while(running) { try { String m =; if(Gameprotocol.isPacket(m, Gameprotocol.CHAT_MESSAGE)) { String mess = Gameprotocol.getAfterPeriod(m); window.logMessage(mess); } else if(Gameprotocol.isPacket(m, Gameprotocol.MOVE_ME)) { window.logMessage("YO we can move"); String mess = Gameprotocol.getAfterPeriod(m); String args[] = Gameprotocol.splitArguments(mess, 3); if(args.length == 3) { int x = Integer.parseInt(args[1]); int y = Integer.parseInt(args[2]); player.moveTo(x, y); window.getFieldObj().drawPlayer(player); window.logMessage("YEP"); } } Thread.sleep(1); } catch(InterruptedException e) { } } } the problem is that my player moves, but sometimes he get's a little lag spike or something.. you know? like stops for millisecond, if i remove the thread.sleep(1), it seems to work okay.. is this plausible? my idea is that if my character wants to move, i send the 'can i walk' packet to the server and server replies and then my character moves/or not.. all i have is chat message system&moving.. should i be worried that my game will be slow or something? i have to add many oter things yet.. q2) i have yet to solve the cheating problem, what i thought is that when client connects to server, server assigns him an id and 24bit hash, id and hash will be combined into one string, like 6bit string so there's like (26 + 10)^6 = 2 176 782 336 IDs.. doesnt seem so secure.. i dont want to make too big control codes too.. because packet sending will take a little more then or so.. + in order to make packets more harder to read and modify by some WPE editors, i should encrypt before sending and decrypt on recieving. is there any other way to go around this? more logical one or better :)? or ehm what about this: on server side i map ID and IP address.. so when somebody sends me packet, where is 3bit ID, i can check if those are equal.. this sounds like i can fake that too although [Edited by - Chr1sen on June 10, 2010 4:56:45 AM]
  5. Scrolling game map.

    hello. this is the rules i have on game scrolling: i dont allow no back(x) scrolling and i only scroll when player's mapx is bigger than before, also i dont let player to go end on screen, i restrict it with this: if(screenx >= SCREEN_W_ / 2 + 50) { screenx = SCREEN_W_ / 2 + 50; } heres the rendering void map_render(int map_drawx, int map_drawy) { static short x, y; static short mapx, mapy; static Tile *tile; // mapx and mapy show where we start rendering map mapx = map_drawx / DEF_TILE_X; map_xoff = map_drawx % DEF_TILE_X; textprintf(buffer, font, 20, 60, makecol(255, 255, 255), "scroll %d", map_xoff); tile = 0; for(x = 0; x <= tiles_per_x; x++) { for(y = 0; y < tiles_per_y; y++) { if(tile = tiles.get_tile(mapx + x, y)) { blit(tile->picture, buffer, 0, 0, x * DEF_TILE_X - map_xoff, y * DEF_TILE_Y, DEF_TILE_X, DEF_TILE_Y); } } } } My problem is that when the scrolling happens, then somehow mapx goes wrong.. seems like i need to add the map_xoff to the person mapx(). but i cant do it because it will mess things up, surely there is another solution how this could be solved?