Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Sending Graphics over net
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Khrist




PostPosted: Thu May 26, 2005 9:09 am   Post subject: Sending Graphics over net

Ive been trying to make a simple lan game for my final project. I understand most of the net commands and can create and successfully run a simple chat server/client. However, ive created numberous offline games which ide like to be able to adapt to online. I cant seem to figure out, or find a post which explains how to send images/graphics anything like that over the stream. If anyone can explain and maybe give an example as to how to do this it would help me out a lot. Thanks
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu May 26, 2005 2:36 pm   Post subject: (No subject)

you've got to send binary information and then reconstruct the file using bits and bites.

I don't remember if Net. can send binary data, so if you're using strings, remember that each character is actually 8 bytes. You'll be able to send 800% more data (well... technically 7/8 less junk) if you are to construct datastrings from binary and then decode. intstr(), strint() and understanding of binary algebra could be of use.
c0bra54




PostPosted: Thu May 26, 2005 2:55 pm   Post subject: (No subject)

wouldn't it be infintly easier.. yet take insanely more time, to simple use whatdotcolour, for every pixel of the screen, and send every single pixel,m and have the client (other end) reconstruct the image use drawdot...

it's insanely more complex.. but would it work.. OR you could write a file compresiong to use in turing, like say

what dot colou pixel 1
what dot colour pixel 2
and thn say if what dot colour pixel 2 is = to whatdot colour pixel 1 then

send (x,y) of pixel 1,

hello client, pixel 2 is the same as pixel 1!!

and poof file compression is born!!! lol

kevin..
PS if you do nytihng with that.. post it it'd be sooo cool
Carino




PostPosted: Thu May 26, 2005 3:53 pm   Post subject: (No subject)

Even if you could send pictures and what not, it would be EXTREMELY slow using turing. I suggest you have all pictures stored on both comps, and then just have the server send the coordinates of specific pics or vise-versa. Then you can just draw the pics using the new coordinates.
Token




PostPosted: Thu May 26, 2005 5:35 pm   Post subject: (No subject)

code:


drawfilloval (maxx div 2, maxy div 2, 200, 200, green)

var file : int
open : file, "picture.txt", put

put : file, maxx, " ", maxy

for x : 1 .. maxx
    for y : 1 .. maxy

        put : file, whatdotcolor (x, y), " " ..
        drawdot (x, y, black)
    end for
end for
close : file

cls

var c : int
var screenx, screeny : string
open : file, "picture.txt", get

get : file, screenx, screeny

setscreen ("graphics:" + screenx + ";" + screeny + ",nobuttonbar")

for x : 1 .. maxx
    for y : 1 .. maxy
        get : file, c
        drawdot (x, y, c)
    end for
end for

close : file


okay, i made this to try and help, but it dosent seem to re-daw or copy it properlly, probibly just a brain fart somewhere along the line, ne ideas?
Cervantes




PostPosted: Thu May 26, 2005 5:57 pm   Post subject: (No subject)

Say we set the graphics of the original screen to 200 by 200:
code:

setscreen ("graphics:200;200,nobuttonbar")

We entered the numbers 200 and 200, but maxx and maxy return values of 199 and 199. You can verify this by looking at your file. So, when we reconstruct the second window, we must add one to your screenx and screeny variables.

Completed code: (I also changed the code a little so we don't have to close then re-open the file.)
code:

setscreen ("graphics:200;200,nobuttonbar")
drawfilloval (maxx div 2, maxy div 2, 100, 100, green)

var file : int
open : file, "picture.txt", put, get, seek

put : file, maxx, " ", maxy

for x : 1 .. maxx
    for y : 1 .. maxy
        put : file, whatdotcolor (x, y), " " ..
        drawdot (x, y, black)
    end for
end for

cls

var c : int
var screenx, screeny : string
seek : file, 0  %move to the beginning of the file.
get : file, screenx, screeny

setscreen ("graphics:" + intstr (strint(screenx)+1) + ";" + intstr (strint(screeny)+1)+ ",nobuttonbar")

for x : 1 .. maxx
    for y : 1 .. maxy
        get : file, c
        drawdot (x, y, c)
    end for
end for

close : file
McKenzie




PostPosted: Thu May 26, 2005 7:19 pm   Post subject: (No subject)

I find takepic the best for this
code:
proc picToASCII(buff:array 1..* of int,var aBuff : array 1..* of string(11))
    for i:1..upper(buff)
        aBuff(i) := intstr(buff(i))
    end for
end picToASCII

proc ASCIIToPic(aBuff : array 1..* of string(11),var buff:array 1..* of int)
    for i:1..upper(buff)
        buff(i) := strint(aBuff(i))
    end for
end ASCIIToPic

for i: 1..50
    drawfillstar(Rand.Int(1,255),Rand.Int(1,255),Rand.Int(1,255),Rand.Int(1,255),Rand.Int(1,255))
end for

var buff,buff2 : array 1..sizepic(0,0,50,50) of int
var aBuff : array 1..upper(buff) of string(11)
for i:1..upper(buff)
    buff(i):=0
end for

takepic(0,0,50,50,buff)
picToASCII(buff,aBuff)
ASCIIToPic(aBuff,buff2)
cls
drawpic(0,0,buff,0)
drawpic(100,0,buff2,0)

Be carefull because I think it only works if you are in the same resolution (or at least colour depth)
Token




PostPosted: Thu May 26, 2005 8:03 pm   Post subject: (No subject)

thanks for the help Cervantes, yah that would be the deciding factor :p ne ways the reason i made it open and close twice is because one side is the client and the other the host, i just havent added the Net commands yet.
Sponsor
Sponsor
Sponsor
sponsor
c0bra54




PostPosted: Thu May 26, 2005 9:54 pm   Post subject: (No subject)

wow guys nice work on this.. but mainly i am thinking, like what about if you wanted o do a sort of paint program.. or somethin like msn whiteboard (if nyone else has used it)

but this is insane.. if anyone wants to swap msn maybe we could setup a net vers and see if it works..

i have router and it won't let me using turing net (tried) so blah Razz
Khrist




PostPosted: Fri May 27, 2005 8:05 am   Post subject: (No subject)

ok ive read over everything and i like the idea of sending variables(x,y) and then just have the client update thier screen. It could use universal variables like x1pos,y1pos,x2pos,y2pos which would be declared on client and server. Then the player 2(x2pos,y2pos) would only be available to change on the client. For instance the controls for player 2 only work on the client and the controls for player 1 only work on server. Then it swaps the co-ords and updates. I dont think ill be able to do a tag game becasue it wouldnt update fast enough. But i have some other ideas.

Anyways im not quite sure how do go about sending variables, i know how to send text but how to you send something that would change the clients vars?

Is it close to this?
code:

if hasch then         
        put : stream, x1pos
        put : stream, y1pos
end if
if Net.LineAvailable (stream) then
        get : stream, x2pos
        get : stream, y2pos
end if


Thats whats in my head but im not sure. Ill go experiment with some things and maybe ill find it out myself, but if not maybe someon could clear it up for me. Thanks again everyone.
c0bra54




PostPosted: Fri May 27, 2005 8:18 am   Post subject: (No subject)

you need to send a header...

a header is somehting at the begining of w/e u send that tells the over machine what you are doing, so like

your getcould be,

get:header

if header = w/e then
get w/e

end if

that way the client knows what it is that it is getting information wise...

it gets to be really long, when you have like 40 differnet things you need to send Razz...

but yeh, use a header
Khrist




PostPosted: Fri May 27, 2005 8:37 am   Post subject: (No subject)

Ok, cobra i read what you wrote but im not really clear on what it means. I asked my teacher if he understood it and he didnt. Would you be able to write a sample code of that snipet just so its a little more clear. Thanks for the help.
c0bra54




PostPosted: Fri May 27, 2005 9:23 am   Post subject: (No subject)

umm yeh sure.. gimme a sec
PS i dun knwo if this will work or not since i un have turing open.. and his hasn't got the net in it

code:

var head :string:=""
var info :string:=""     
var xpos :int := 200
var ypos :int :=200
var colour:string :="blue"

loop
get head
get info

if head ="xpos" then
        xpos += strint(info)
elsif head="ypos" then
        ypos +=strint(info)
elsif head = "colour" then
        colour := info
end if

end loop


this is an example, where the user oulkd enter the name of what he wants to change, then the new value... and you have a header var which is what is being changed, and then an info var for the data that is being sent...

you could also do this in an array format which could meen you don't need to send a header.. like the other machine knows that

data(1) is xpos
data(2) is ypos
data(3) is colour or w/e \

the only problem with that is it needs to send all of them, other wise the machine reciving will get messed up... because remeber you can only send text... so even if something didn't change you'd still need to send it...



Razz

hope that clears things up.. if not tell me
Carino




PostPosted: Fri May 27, 2005 10:39 am   Post subject: (No subject)

I made a net pong game, and i tried transfering variables various ways. One way was to have one stream for each variable then just send the info through the stream when need be. Another way i did it was to add a number to each variable, such as 1000 to the x, and 2000 to the y variable. Then i would have an if statement checking each number such as:

code:

if someVar > 2000 then
    newy := y - 2000 %take off the added number
elsif someVar > 1000 then
    newx := x - 1000
end if


Either way though, it was really slow. It worked, but slowly.
McKenzie




PostPosted: Fri May 27, 2005 4:33 pm   Post subject: (No subject)

I find it's best if you only pass the players moves over the net. Take a look at my connect 4. Very simple system.


net1.t
 Description:

Download
 Filename:  net1.t
 Filesize:  1.92 KB
 Downloaded:  127 Time(s)


connect4b.t
 Description:

Download
 Filename:  connect4b.t
 Filesize:  4.15 KB
 Downloaded:  130 Time(s)

Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 16 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: