Search Results

Search found 21759 results on 871 pages for 'int'.

Page 22/871 | < Previous Page | 18 19 20 21 22 23 24 25 26 27 28 29  | Next Page >

  • Draw Bug 2D player Camera

    - by RedShft
    I have just implemented a 2D player camera for my game, everything works properly except the player on the screen jitters when it moves between tiles. What I mean by jitter, is that if the player is moving the camera updates the tileset to be drawn and if the player steps to the right, the camera snaps that way. The movement is not smooth. I'm guessing this is occurring because of how I implemented the function to calculate the current viewable area or how my draw function works. I'm not entirely sure how to fix this. This camera system was entirely of my own creation and a first attempt at that, so it's very possible this is not a great way of doing things. My camera class, pulls information from the current tileset and calculates the viewable area. Right now I am targettng a resolution of 800 by 600. So I try to fit the appropriate amount of tiles for that resolution. My camera class, after calculating the current viewable tileset relative to the players location, returns a slice of the original tileset to be drawn. This tileset slice is updated every frame according to the players position. This slice is then passed to the map class, which draws the tile on screen. //Map Draw Function //This draw function currently matches the GID of the tile to it's location on the //PNG file of the tileset and then draws this portion on the screen void Draw(SDL_Surface* background, int[] _tileSet) { enforce( tilesetImage != null, "Tileset is null!"); enforce( background != null, "BackGround is null!"); int i = 0; int j = 0; SDL_Rect DestR, SrcR; SrcR.x = 0; SrcR.y = 0; SrcR.h = 32; SrcR.w = 32; foreach(tile; _tileSet) { //This code is matching the current tiles ID to the tileset image SrcR.x = cast(short)(tileWidth * (tile >= 11 ? (tile - ((tile / 10) * 10) - 1) : tile - 1)); SrcR.y = cast(short)(tileHeight * (tile > 10 ? (tile / 10) : 0)); //Applying the tile to the surface SDL_BlitSurface( tilesetImage, &SrcR, background, &DestR ); //this keeps track of what column/row we are on i++; if ( i == mapWidth ) { i = 0; j++; } DestR.x = cast(short)(i * tileWidth); DestR.y = cast(short)(j * tileHeight); } } //Camera Class class Camera { private: //A rectangle representing the view area SDL_Rect viewArea; //In number of tiles int viewAreaWidth; int viewAreaHeight; //This is the x and y coordinate of the camera in MAP SPACE IN PIXELS vect2 cameraCoordinates; //The player location in map space IN PIXELS vect2 playerLocation; //This is the players location in screen space; vect2 playerScreenLoc; int playerTileCol; int playerTileRow; int cameraTileCol; int cameraTileRow; //The map is stored in a single array with the tile ids //this corresponds to the index of the starting and ending tile int cameraStartTile, cameraEndTile; //This is a slice of the current tile set int[] tileSetCopy; int mapWidth; int mapHeight; int tileWidth; int tileHeight; public: this() { this.viewAreaWidth = 25; this.viewAreaHeight = 19; this.cameraCoordinates = vect2(0, 0); this.playerLocation = vect2(0, 0); this.viewArea = SDL_Rect (0, 0, 0, 0); this.tileWidth = 32; this.tileHeight = 32; } void Init(vect2 playerPosition, ref int[] tileSet, int mapWidth, int mapHeight ) { playerLocation = playerPosition; this.mapWidth = mapWidth; this.mapHeight = mapHeight; CalculateCurrentCameraPosition( tileSet, playerPosition ); //writeln( "Tile Set Copy: ", tileSetCopy ); //writeln( "Orginal Tile Set: ", tileSet ); } void CalculateCurrentCameraPosition( ref int[] tileSet, vect2 playerPosition ) { playerLocation = playerPosition; playerTileCol = cast(int)((playerLocation.x / tileWidth) + 1); playerTileRow = cast(int)((playerLocation.y / tileHeight) + 1); //writeln( "Player Tile (Column, Row): ","(", playerTileCol, ", ", playerTileRow, ")"); cameraTileCol = playerTileCol - (viewAreaWidth / 2); cameraTileRow = playerTileRow - (viewAreaHeight / 2); CameraMapBoundsCheck(); //writeln( "Camera Tile Start (Column, Row): ","(", cameraTileCol, ", ", cameraTileRow, ")"); cameraStartTile = ( (cameraTileRow - 1) * mapWidth ) + cameraTileCol - 1; //writeln( "Camera Start Tile: ", cameraStartTile ); cameraEndTile = cameraStartTile + ( viewAreaWidth * viewAreaHeight ) * 2; //writeln( "Camera End Tile: ", cameraEndTile ); tileSetCopy = tileSet[cameraStartTile..cameraEndTile]; } vect2 CalculatePlayerScreenLocation() { cameraCoordinates.x = cast(float)(cameraTileCol * tileWidth); cameraCoordinates.y = cast(float)(cameraTileRow * tileHeight); playerScreenLoc = playerLocation - cameraCoordinates + vect2(32, 32);; //writeln( "Camera Coordinates: ", cameraCoordinates ); //writeln( "Player Location (Map Space): ", playerLocation ); //writeln( "Player Location (Screen Space): ", playerScreenLoc ); return playerScreenLoc; } void CameraMapBoundsCheck() { if( cameraTileCol < 1 ) cameraTileCol = 1; if( cameraTileRow < 1 ) cameraTileRow = 1; if( cameraTileCol + 24 > mapWidth ) cameraTileCol = mapWidth - 24; if( cameraTileRow + 19 > mapHeight ) cameraTileRow = mapHeight - 19; } ref int[] GetTileSet() { return tileSetCopy; } int GetViewWidth() { return viewAreaWidth; } }

    Read the article

  • Why does my int, booleans, doubles does not work?

    - by SystemNetworks
    As you see, my code does not work. When armor1 is true, it would add my life. goldA is another class. public void goldenArmor(GameContainer gc, StateBasedGame sbg, Graphics g) { if(armor1==true) { goldA.life = life; goldA.intelligence = intelligence; goldA.power = power; goldA.lifeLeft = lifeLeft; goldA.head(); goldA.body(); goldA.legs(); } } My other class: package javagame; import org.newdawn.slick.GameContainer; import org.newdawn.slick.Graphics; import org.newdawn.slick.Image; import org.newdawn.slick.Input; import org.newdawn.slick.SlickException; /* Note: Copyright(C)2012 System Networks | Square NET | Julius Bryan Gambe. You cannot copy the style, story of the game and gameplay! To programmers: The int,doubles,strings,booleans are properly sorted out. Please don't mess it up. */ /* NOTE: We have loops but not for programming. The loop is: 1.show the world to user 2.Obtain input from the user 3.Shows the update, repeat step 1 */ import org.newdawn.slick.*; import org.newdawn.slick.state.*; import org.lwjgl.input.Mouse; //contents: // public class GoldenArmor{ //get it from play public int life; public double intelligence; public int lifeLeft; public double power; public GoldenArmor() { // TODO Auto-generated constructor stub } //start here public void head() { life += 10; intelligence +=0.5; } public void body() { lifeLeft += 100; } public void legs() { power += 100; } } /* SYSTEM NETWORKS(C) 2012 NET FRONT */ The life, intelligence, power, lifeLeft are nothing but to use it as just reference to prevent stack overflow. And at my main class, it becomes my real booleans, int, doubles. How do I fix this? It does not add it to my normal int.

    Read the article

  • Collision disturbing the jumping mechanic in java 2D game [on hold]

    - by user50931
    So I have been working on a 2D Java game recently and everything was going smoothly, until I reached a problem to do with the players jumping mechanic. So far I've got the player to jump a fixed rate and fall due to gravity. Hers my code for my Player class. public class Player extends GameObject { public Player(int x, int y, int width, int height, ObjectId id) { super(x, y, width, height, id); } @Override public void tick(ArrayList<GameObject> object) { if(go){ x+=vx; y+=vy; } if(vx <0){ facing =-1; }else if(vx >0) facing =1; checkCollision(object); checkStance(); } private void checkStance() { if(falling){ //gravity jumping = false; vy = speed/2; } if(jumping){ // Calculates how high jump should be vy = -speed*2; if(jumpY - y >= maxJumpHeight) falling =true; } } private void checkCollision(ArrayList<GameObject> object) { for(int i=0; i< object.size(); i++ ){ GameObject tempObject = object.get(i); if(tempObject.getId() == ObjectId.Ledge){ if(getBoundsTop().intersects(tempObject.getBoundsAll())){ //Top y = tempObject.getY() + tempObject.getBoundsAll().height; falling =true; } if(getBoundsRight().intersects(tempObject.getBoundsAll())){ // Right x = tempObject.getX() -width ; } if(getBoundsLeft().intersects(tempObject.getBoundsAll())){ //Left x = tempObject.getX() + tempObject.getWidth(); } if(getBoundsBottom().intersects(tempObject.getBoundsAll())){ //Bottom y = tempObject.getY() - height; falling =false; vy=0; }else{ falling =true; } } } } @Override public void render(Graphics g) { g.setColor(Color.BLACK); g.fillRect((int)x, (int)y, width, height); } @Override public Rectangle getBoundsAll() { return new Rectangle((int)x, (int)y,width,height); } public Rectangle getBoundsTop() { return new Rectangle((int) x , (int)y ,width,height/15); } public Rectangle getBoundsBottom() { return new Rectangle( (int)x , (int) y +height -(height /15),width,height/15); } public Rectangle getBoundsLeft() { return new Rectangle( (int) x , (int) y + height /10 ,width/8,height - (height /5)); } public Rectangle getBoundsRight() { return new Rectangle((int) x + width - (width/8) ,(int) y + height /10 ,width/8,height - height/5); } } My problem is when I add: else{ falling =true; } during the loop of the ArrayList to check collision, it stops the player from jumping and keeps him on the ground. I've tried to find a way around this but haven't had any luck. Any suggestions?

    Read the article

  • Visual Studio Wcf Test Client - entering an Int array

    - by WebDude
    Hi, I've found the Visual Studio WCF test client quite useful when it comes to a quick test of my WCF service. This is the test client found in this location relative to your Visual Studio install directory: \Common7\IDE\WcfTestClient.exe I have a few service calls that require a parameter of type System.Int32[] I can't seem to figure out what values to enter against for this parameter as i keep receiving the error '[value entered]' is not a valid value for this type Trying to enter the value 27 i have tried the following, but all fails 27 { 27 } new System.Int32[] { 27 } Can anyone please help with how to do this

    Read the article

  • int.ToString like HH formatted of DateTime

    - by nCdy
    ("dd/MM/yyyy HH")+ " - " + (x.Hour+1).ToString(); So here is example what I got and what I need : 0 ---> 00 3 ---> 03 12 ---> 12 How can I use ToString for it ? I've tried : x.ToString("dd/MM/yyyy HH") + " - " + x.AddHours(1).ToString("HH"); doesn't works ...

    Read the article

  • Storing objects in the array

    - by Ockonal
    Hello, I want to save boost signals objects in the map (association: signal name ? signal object). The signals signature is different, so the second type of map should be boost::any. map<string, any> mSignalAssociation; The question is how to store objects without defining type of new signal signature? typedef boost::signals2::signal<void (int KeyCode)> sigKeyPressed; mSignalAssociation.insert(make_pair("KeyPressed", sigKeyPressed())); // This is what I need: passing object without type definition mSignalAssociation["KeyPressed"] = (typename boost::signals2::signal<void (int KeyCode)>()); // One more trying which won't work. And I don't want use this sigKeyPressed mKeyPressed; mSignalAssociation["KeyPressed"] = mKeyPressed; All this tryings throw the error: /usr/include/boost/noncopyable.hpp: In copy constructor ‘boost::signals2::signal_base::signal_base(const boost::signals2::signal_base&)’: In file included from /usr/include/boost/signals2/detail/signals_common.hpp:17:0, /usr/include/boost/noncopyable.hpp:27:7: error: ‘boost::noncopyable_::noncopyable::noncopyable(const boost::noncopyable_::noncopyable&)’ is private /usr/include/boost/signals2/signal_base.hpp:22:5: error: within this context ---------- /usr/include/boost/signals2/detail/signal_template.hpp: In copy constructor ‘boost::signals2::signal1<void, int&, boost::signals2::optional_last_value<void>, int, std::less<int>, boost::function<void(int)>, boost::function<void(const boost::signals2::connection&, int)>, boost::signals2::mutex>::signal1(const boost::signals2::signal1<void, int, boost::signals2::optional_last_value<void>, int, std::less<int>, boost::function<void(int)>, boost::function<void(const boost::signals2::connection&, int)>, boost::signals2::mutex>&)’: In file included from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:52:0, /usr/include/boost/signals2/detail/signal_template.hpp:578:5: note: synthesized method ‘boost::signals2::signal_base::signal_base(const boost::signals2::signal_base&)’ first required here from /usr/include/boost/signals2.hpp:16, --------- /usr/include/boost/signals2/preprocessed_signal.hpp: In copy constructor ‘boost::signals2::signal<void(int)>::signal(const boost::signals2::signal<void(int)>&)’: In file included from /usr/include/boost/signals2/signal.hpp:36:0, /usr/include/boost/signals2/preprocessed_signal.hpp:42:5: note: synthesized method ‘boost::signals2::signal1<void, int, boost::signals2::optional_last_value<void>, int, std::less<int>, boost::function<void(int)>, boost::function<void(const boost::signals2::connection&, int)>, boost::signals2::mutex>::signal1(const boost::signals2::signal1<void, int, boost::signals2::optional_last_value<void>, int, std::less<int>, boost::function<void(int)>, boost::function<void(const boost::signals2::connection&, int)>, boost::signals2::mutex>&)’ first required here from /home/ockonal/Workspace/Projects/Pseudoform-2/include/Core/Systems.hpp:6,

    Read the article

  • Unable to convert from Julian INT date to regular TSQL Datetime

    - by Bluehiro
    Help me Stackoverflow, I'm close to going all "HULK SMASH" on my keyboard over this issue. I have researched carefully but I'm obviously not getting something right. I am working with a Julian dates referenced from a proprietary tool (Platinum SQL?), though I'm working in SQL 2005. I can convert their "special" version of Julian into datetime when I run a select statement. Unfortunately it will not insert into a datetime column, I get the following error when I try: The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. So I can't setup datetime criteria for running a report off of the Stored Procedure. Original Value: 733416 Equivalent Calendar Value: 01-09-2009 Below is my code... I'm so close but I can't quite see what's wrong, I need my convert statement to actually convert the Julian value (733416) into a compatible TSQL DATETIME value. SELECT org_id, CASE WHEN date_applied = 0 THEN '00-00-00' ELSE convert(char(50),dateadd(day,date_applied-729960,convert(datetime, '07-25-99')),101) END AS date_applied, CASE WHEN date_posted = 0 THEN '00-00-00' ELSE convert(char(50),dateadd(day,date_posted-729960,convert(datetime, '07-25-99')),101) END AS date_posted from general_vw

    Read the article

  • Using [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("System.Windows")] To expose Int

    - by Anthony
    Ok so I had a qustion awhile back regarding Silverlight 4 Data Binding with anonymous types, one of the answers was to use [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("System.Windows")] in your AssemblyInfo.cs file. I tried this and it works! I know I'm making all my internal properties classes and methods visible to the System.Windows Assembley. But what kind of risk is this with the following in mind: The product is a hosted silverlight based web application, so it wont be distributed. Thanks in advance

    Read the article

  • Scala n00b: Critique my code

    - by Peter
    G'day everyone, I'm a Scala n00b (but am experienced with other languages) and am learning the language as I find time - very much enjoying it so far! Usually when learning a new language the first thing I do is implement Conway's Game of Life, since it's just complex enough to give a good sense of the language, but small enough in scope to be able to whip up in a couple of hours (most of which is spent wrestling with syntax). Anyhoo, having gone through this exercise with Scala I was hoping the Scala gurus out there might take a look at the code I've ended up with and provide feedback on it. I'm after anything - algorithmic improvements (particularly concurrent solutions!), stylistic improvements, alternative APIs or language constructs, disgust at the length of my function names - whatever feedback you've got, I'm keen to hear it! You should be able to run the following script via "scala GameOfLife.scala" - by default it will run a 20x20 board with a single glider on it - please feel free to experiment. // CONWAY'S GAME OF LIFE (SCALA) abstract class GameOfLifeBoard(val aliveCells : Set[Tuple2[Int, Int]]) { // Executes a "time tick" - returns a new board containing the next generation def tick : GameOfLifeBoard // Is the board empty? def empty : Boolean = aliveCells.size == 0 // Is the given cell alive? protected def alive(cell : Tuple2[Int, Int]) : Boolean = aliveCells contains cell // Is the given cell dead? protected def dead(cell : Tuple2[Int, Int]) : Boolean = !alive(cell) } class InfiniteGameOfLifeBoard(aliveCells : Set[Tuple2[Int, Int]]) extends GameOfLifeBoard(aliveCells) { // Executes a "time tick" - returns a new board containing the next generation override def tick : GameOfLifeBoard = new InfiniteGameOfLifeBoard(nextGeneration) // The next generation of this board protected def nextGeneration : Set[Tuple2[Int, Int]] = aliveCells flatMap neighbours filter shouldCellLiveInNextGeneration // Should the given cell should live in the next generation? protected def shouldCellLiveInNextGeneration(cell : Tuple2[Int, Int]) : Boolean = (alive(cell) && (numberOfAliveNeighbours(cell) == 2 || numberOfAliveNeighbours(cell) == 3)) || (dead(cell) && numberOfAliveNeighbours(cell) == 3) // The number of alive neighbours for the given cell protected def numberOfAliveNeighbours(cell : Tuple2[Int, Int]) : Int = aliveNeighbours(cell) size // Returns the alive neighbours for the given cell protected def aliveNeighbours(cell : Tuple2[Int, Int]) : Set[Tuple2[Int, Int]] = aliveCells intersect neighbours(cell) // Returns all neighbours (whether dead or alive) for the given cell protected def neighbours(cell : Tuple2[Int, Int]) : Set[Tuple2[Int, Int]] = Set((cell._1-1, cell._2-1), (cell._1, cell._2-1), (cell._1+1, cell._2-1), (cell._1-1, cell._2), (cell._1+1, cell._2), (cell._1-1, cell._2+1), (cell._1, cell._2+1), (cell._1+1, cell._2+1)) // Information on where the currently live cells are protected def xVals = aliveCells map { cell => cell._1 } protected def xMin = (xVals reduceLeft (_ min _)) - 1 protected def xMax = (xVals reduceLeft (_ max _)) + 1 protected def xRange = xMin until xMax + 1 protected def yVals = aliveCells map { cell => cell._2 } protected def yMin = (yVals reduceLeft (_ min _)) - 1 protected def yMax = (yVals reduceLeft (_ max _)) + 1 protected def yRange = yMin until yMax + 1 // Returns a simple graphical representation of this board override def toString : String = { var result = "" for (y <- yRange) { for (x <- xRange) { if (alive (x,y)) result += "# " else result += ". " } result += "\n" } result } // Equality stuff override def equals(other : Any) : Boolean = { other match { case that : InfiniteGameOfLifeBoard => (that canEqual this) && that.aliveCells == this.aliveCells case _ => false } } def canEqual(other : Any) : Boolean = other.isInstanceOf[InfiniteGameOfLifeBoard] override def hashCode = aliveCells.hashCode } class FiniteGameOfLifeBoard(val boardWidth : Int, val boardHeight : Int, aliveCells : Set[Tuple2[Int, Int]]) extends InfiniteGameOfLifeBoard(aliveCells) { override def tick : GameOfLifeBoard = new FiniteGameOfLifeBoard(boardWidth, boardHeight, nextGeneration) // Determines the coordinates of all of the neighbours of the given cell override protected def neighbours(cell : Tuple2[Int, Int]) : Set[Tuple2[Int, Int]] = super.neighbours(cell) filter { cell => cell._1 >= 0 && cell._1 < boardWidth && cell._2 >= 0 && cell._2 < boardHeight } // Information on where the currently live cells are override protected def xRange = 0 until boardWidth override protected def yRange = 0 until boardHeight // Equality stuff override def equals(other : Any) : Boolean = { other match { case that : FiniteGameOfLifeBoard => (that canEqual this) && that.boardWidth == this.boardWidth && that.boardHeight == this.boardHeight && that.aliveCells == this.aliveCells case _ => false } } override def canEqual(other : Any) : Boolean = other.isInstanceOf[FiniteGameOfLifeBoard] override def hashCode : Int = { 41 * ( 41 * ( 41 + super.hashCode ) + boardHeight.hashCode ) + boardWidth.hashCode } } class GameOfLife(initialBoard: GameOfLifeBoard) { // Run the game of life until the board is empty or the exact same board is seen twice // Important note: this method does NOT necessarily terminate!! def go : Unit = { var currentBoard = initialBoard var previousBoards = List[GameOfLifeBoard]() while (!currentBoard.empty && !(previousBoards contains currentBoard)) { print(27.toChar + "[2J") // ANSI: clear screen print(27.toChar + "[;H") // ANSI: move cursor to top left corner of screen println(currentBoard.toString) Thread.sleep(75) // Warning: unbounded list concatenation can result in OutOfMemoryExceptions ####TODO: replace with LRU bounded list previousBoards = List(currentBoard) ::: previousBoards currentBoard = currentBoard tick } // Print the final board print(27.toChar + "[2J") // ANSI: clear screen print(27.toChar + "[;H") // ANSI: move cursor to top left corner of screen println(currentBoard.toString) } } // Script starts here val simple = Set((1,1)) val square = Set((4,4), (4,5), (5,4), (5,5)) val glider = Set((2,1), (3,2), (1,3), (2,3), (3,3)) val initialBoard = glider (new GameOfLife(new FiniteGameOfLifeBoard(20, 20, initialBoard))).go //(new GameOfLife(new InfiniteGameOfLifeBoard(initialBoard))).go // COPYRIGHT PETER MONKS 2010 Thanks! Peter

    Read the article

  • Assigning static final int in a JUnit (4.8.1) test suite

    - by Dr. Monkey
    I have a JUnit test class in which I have several static final ints that can be redefined at the top of the tester code to allow some variation in the test values. I have logic in my @BeforeClass method to ensure that the developer has entered values that won't break my tests. I would like to improve variation further by allowing these ints to be set to (sensible) random values in the @BeforeClass method if the developer sets a boolean useRandomValues = true;. I could simply remove the final keyword to allow the random values to overwrite the initialisation values, but I have final there to ensure that these values are not inadvertently changed, as some tests rely on the consistency of these values. Can I use a constructor in a JUnit test class? Eclipse starts putting red underlines everywhere if I try to make my @BeforeClass into a constructor for the test class, and making a separate constructor doesn't seem to allow assignment to these variables (even if I leave them unassigned at their declaration); Is there another way to ensure that any attempt to change these variables after the @BeforeClass method will result in a compile-time error? Can I make something final after it has been initialised?

    Read the article

  • Fastest sort of fixed length 6 int array

    - by kriss
    Answering to another StackOverflow question (this one) I stumbled upon an interresting sub-problem. What is the fastest way to sort an array of 6 ints ? As the question is very low level (will be executed by a GPU): we can't assume libraries are available (and the call itself has it's cost), only plain C to avoid emptying instruction pipeline (that has a very high cost) we should probably minimize branches, jumps, and every other kind of control flow breaking (like those hidden behind sequence points in && or ||). room is constrained and minimizing registers and memory use is an issue, ideally in place sort is probably best. Really this question is a kind of Golf where the goal is not to minimize source length but execution speed. I call it 'Zening` code as used in the title of the book Zen of Code optimization by Michael Abrash and it's sequels.

    Read the article

  • Best way to do powerOf(int x, int n)?

    - by Mike
    So given x, and power, n, solve for X^n. There's the easy way that's O(n)... I can get it down to O(n/2), by doing numSquares = n/2; numOnes = n%2; return (numSquares * x * x + numOnes * x); Now there's a log(n) solution, does anyone know how to do it? It can be done recursively.

    Read the article

  • Isn't INT more efficient than UNIQUEIDENTIFIER?

    - by ck
    I have a parent table and child table where the columns that join them together are the UNIQUEIDENTIFIER type. The child table has a clustered index on the column that joins it to the parent table (its PK, which is also clustered). I have created a copy of both of these tables but changed the relationship columns to be INTs instead, have rebuilt the indexes so that they are essentially the same structure and can be queried in the same way. When I query for a known 20 records from the parent table, pulling in all the related records from the child tables, I get identical query costs across both, i.e. 50/50 cost for the batches. If this is true, then my giant project to change all of the tables like this appears to be pointless, other than speeding up inserts. Can anyone provide any light on the situation?

    Read the article

  • Interrupt an Http Request blocked in read() on Android

    - by twk
    Using the Apache Http stack on Android, I'm trying to force a thread out of a call to read. This is what the stack looks like: OSNetworkSystem.receiveStreamImpl(FileDescriptor, byte[], int, int, int) line: not available [native method] OSNetworkSystem.receiveStream(FileDescriptor, byte[], int, int, int) line: 478 PlainSocketImpl.read(byte[], int, int) line: 565 SocketInputStream.read(byte[], int, int) line: 87 SocketInputBuffer(AbstractSessionInputBuffer).fillBuffer() line: 103 SocketInputBuffer(AbstractSessionInputBuffer).read(byte[], int, int) line: 134 IdentityInputStream.read(byte[], int, int) line: 86 EofSensorInputStream.read(byte[], int, int) line: 159 Fetcher.readStream() line: 89 I've tried InputStream.close(), Thread.Interrupt(), and HttpUriRequest.abort(), without any success. Any ideas? I'm also open to some kind of non-blocking IO, but I don't see any way to do that with the HttpUriRequest object. Thanks!

    Read the article

  • Getting a char array from a vector<int>?

    - by Legend
    I am trying to pass a value from C++ to TCL. As I cannot pass pointers without the use of some complicated modules, I was thinking of converting a vector to a char array and then passing this as a null terminated string (which is relatively easy). I have a vector as follows: 12, 32, 42, 84 which I want to convert into something like: "12 32 42 48" The approach I am thinking of is to use an iterator to iterate through the vector and then convert each integer into its string representation and then add it into a char array (which is dynamically created initially by passing the size of the vector). Is this the right way or is there a function that already does this?

    Read the article

  • seperating interface and implemention with normal functions

    - by ace
    this seems like it should be pretty simple, im probably leaving something simple out. this is the code im trying to run. it is 3 files, 2*cpp and 1*header. -------------lab6.h ifndef LAB6_H_INCLUDED define LAB6_H_INCLUDED int const arraySize = 10; int array1[arraySize]; int array2[arraySize]; void generateArray(int[], int ); void displayArray(int[], int[], int ); void reverseOrder(int [],int [], int); endif // LAB6_H_INCLUDED -----------------lab6.cpp include using std::cout; using std::endl; include using std::rand; using std::srand; include using std::time; include using std::setw; include "lab6.h" void generateArray(int array1[], int arraySize) { srand(time(0)); for (int i=0; i<10; i++) { array1[i]=(rand()%10); } } void displayArray(int array1[], int array2[], int arraySize) { cout<<endl<<"Array 1"<<endl; for (int i=0; i<arraySize; i++) { cout<<array1[i]<<", "; } cout<<endl<<"Array 2"<<endl; for (int i=0; i<arraySize; i++) { cout<<array2[i]<<", "; } } void reverseOrder(int array1[],int array2[], int arraySize) { for (int i=0, j=arraySize-1; i<arraySize;j--, i++) { array2[j] = array1[i]; } } ------------and finally main.cpp include "lab6.h" int main() { generateArray(array1, arraySize); reverseOrder(array1, array2, arraySize); displayArray(array1, array2, arraySize); return 0; }

    Read the article

  • php switch statement error on int = 0

    - by Jagdeep Singh
    I am having a problem in php switch case. When i set $number=0 it should run very first case but here this code returns 10-20K that is in second case. I checked comparison operators, tested them in if else case they return correct values but here first case do not run on $number=0 Why is this happening ? php consider 0 as false or something wrong in code ? Link to codepad paste http://codepad.org/2glDh39K also here is the code <?php $number = 0; switch ($number) { case ($number <= 10000): echo "0-10K"; break; case ($number > 10000 && $number <= 20000): echo "10-20K"; break; case ($number > 20000 && $number <= 30000): echo "20-30K"; break; case ($number > 30000 && $number <= 40000): echo "30-40K"; break; case ($number > 40000 && $number <= 50000): echo "40-50K"; break; case ($number > 50000 && $number <= 60000): echo "50-60K"; break; case ($number > 60000 && $number <= 70000): echo "60-70K"; break; case ($number > 70000 && $number <= 80000): echo "70-80K"; break; case ($number > 80000 && $number <= 90000): echo "80-90K"; break; case ($number > 90000): echo "90K+"; break; default: //default echo "N/A"; break; } ?>

    Read the article

  • int vs NSNumber vs NSInteger

    - by Moshe
    I have a line of code that will work differently depending on the datatypes "day" and "1". I believe it is the following although I will check my source code later. day = day + 1; Does this make sense? What would the differences be?

    Read the article

  • Faster float to int conversion in Python

    - by culebrón
    Here's a piece of code that takes most time in my program, according to timeit statistics. It's a dirty function to convert floats in [-1.0, 1.0] interval into unsigned integer [0, 2**32]. How can I accelerate floatToInt? piece = [] rng = range(32) for i in rng: piece.append(1.0/2**i) def floatToInt(x): n = x + 1.0 res = 0 for i in rng: if n >= piece[i]: res += 2**(31-i) n -= piece[i] return res

    Read the article

  • Replace into equivalent for postgresql and then autoincrementing an int

    - by Mohamed Ikal Al-Jabir
    Okay no seriously, if a postgresql guru can help out I'm just getting started. Basically what I want is a simple table like such: CREATE TABLE schema.searches ( search_id serial NOT NULL, search_query character varying(255), search_count integer DEFAULT 1, CONSTRAINT pkey_search_id PRIMARY KEY (search_id) ) WITH ( OIDS=FALSE ); I need something like REPLACE INTO for mysql. I don't know if I have to write my own procedure or something? Basically: check if the query already exists if so, just add 1 to the count it not, add it to the db I can do this in my php code but I'd rather all that be done in postgres C engine Thanks for helping

    Read the article

< Previous Page | 18 19 20 21 22 23 24 25 26 27 28 29  | Next Page >