• Advertisement

aptpatzer

Member
  • Content count

    16
  • Joined

  • Last visited

Community Reputation

1 Neutral

1 Follower

About aptpatzer

  • Rank
    Member

Personal Information

  • Interests
    Design
    Education
    Programming
  1. Ray casting question

    I am currently designing a ray caster demo in html5. I understand ray casting in general but I don't understand how to calculate collisions of rays with lines on the grid. At a given frame, the camera is projecting rays outwards at various angles. Each ray intersects grid lines until it hits one that is a wall of sprite or something. My question is, how mathematically do I calculate all these intersections? It seems like there are a lot of cases I have to consider for each "square" the ray is passing through to determine which wall of the square it is hitting on its way out.
  2. Hierarchical Data in a Web Application

    In case anyone is interested (probably not) I ended up declining the offer, hiring some staff to expand production. Then while we were shopping for an office space, the original offerers came back with a 180% hike to their offer (almost tripled). I caved. As fun as the project was and as much as I was loving having correspondence with big people in the industry that I've admired for years, it's time to provide for my family.. and extended family.. and friends.. for multiple lifetimes!
  3. Hierarchical Data in a Web Application

    #2 would probably be the main draw for me I currently have about 1.5 million unique users per day that perform client-side operations that result in modifications to their personal "tree" of data. So performance is definitely an issue. Average user modifies their information about 80 times a day and the data I'm gathering from them has enabled me to do some optimizations that preclude the need to worry about this issue in the short term. In about a month, the people offering to buy this service from me predict we'll need better methods since volume is roughly doubling per week. Ask me a week ago and I'd be more stressed out about how I was going to solve this since it was just a personal project. I also wasn't sure how I was going to make rent Now I can hire people and I have an unbelievably huge offer that I'm considering taking for acquisition of this service. If I don't accept, it'll be because retiring is less important to me than remaining an active industry-shaping force in a field I am passionate about, and I'll be hiring several full time people to take this workload off my hands.
  4. Hierarchical Data in a Web Application

    Yes just decorating it manually for the time being. Kylotan didn't mention why he preferred JSON for this application to XML but I'm going to assume he had a good reason and switch over to JSON for what I'm doing. As you suggested, I'd like to automate the conversion process. It took me a little bit to figure out a nice algorithm for converting hierarchical data whose hierarchical nature is expressed by indentation to a tree, but once I got that working, I realized I should be able to make something that generates a JSON. My algorithm involves a stack of references to nodes plus one extra reference not in the stack. I could put that extra one on the stack and make the algorithm more expressible, but that just results in a lot of superfluous pushes and pops.
  5. Hierarchical Data in a Web Application

    I see. But is that better than using XML instead? XML can also turn into an object with DOMParser().parseFromString(text,"text/xml") I'm just trying to understand the advantage of using JSON here. Taking my raw text data and converting it into JSON format seems like a lot more work than just appending and prepending tags to convert it into the XML format. But I'm sure I'm probably not understanding what you're suggesting here.
  6. Hierarchical Data in a Web Application

    I am familiar with JSON strings. But I don't see how I can use them here. Currently the data is in a huge text file where child/parent relationships are expressed via tab indention. It's an ugly mess. How do I take that and convert it into a JSON. And why would JSON be any better than just prepending each line with tags and treating it as an XML string and using DOMParser().parseFromString(text,"text/xml")?
  7. Hierarchical Data in a Web Application

    So does that mean I should store it the way I did in my code example? My only issue with that is it's cumbersome. It's because javascript doesn't allow new lines in strings without escape characters.
  8. I am creating an HTML5 game. Part of the content of the game is based on some hierarchical data. I need to take this data and load it into a tree data structure. I have my tree data structure working but I need to figure out exactly how to store the data. After much frustrating trial and error I realized that for all intents and purposes it's not possible to pull data into Javascript. So I couldn't have an XML file sitting in the same directory as the html and javascript files and load it and parse it. I found it utterly amazing that there was no workaround for this other than using node.js or something which I don't currently want to do. So given that that is impossible, which again is amazing since an HTML file can load in javascript files and images and other various sources, how would I store and process my hierarchical data? For the purposes of the question, assume the hierarchical data is basically of a form that would be conducive to the XML format. Currently my solution, which is extremely ugly and cumbersome is to handcode the data into javascript like this: var text = "<note>"+ "<to>Tove</to>"+ " <from>Jani</from>"+ "<heading>Reminder</heading>"+ "<body>Don't forget me this weekend!</body>"+ "</note>";
  9. Optimizing a scrolling view

    This immediately strikes me as feasible and very interesting. Thank you for the suggestion. It's definitely something I will try to implement. I have an idea involving a pair of binary searches (one per dimension)
  10. Do you know of a bare bones C# / HTML5 example I could paste, run, and then deconstruct? That's how I learn fastest. I could go about building up to it like you said but that will take me much longer. I've gotten full server/clients communicating and sending messages with a C# client and server. And I've gotten HTML5 clients talking to echo servers. But I haven't been able to find a good resources for making a C# websocket server that my HTML5 client could talk to.
  11. When I moved the client = server.AcceptTcpClient(); above the start of the loop, what I got was that that initial handshake was longer and contained a lot more weird information, but that attempts to "send testmessage" from the client would still have nothing happen serverside.
  12. I'm attempting to create a bare bones websocket chat room server. My client is able to connect to the server, but it is unable to send messages to the server, despite the server being in a listening state. When the client connects, a bunch of what looks like header information gets written to the console. But when WebSocket.send() gets executed in Javascript, nothing occurs server side. HTML: <button id="closeSocket">disconnect</button><br /> <input id = "inputField" /><button id="sendMessage">send</button> <div id = "output"></div> <script type = 'text/javascript' src = 'websockets.js'></script> Javascript: websocket = new WebSocket("ws://127.0.0.1:80"); document.getElementById("closeSocket").onclick = closeSocket; document.getElementById("sendMessage").onclick = sendMessage; websocket.onopen = function(){ output("connected"); } function sendMessage(){ output("sent: " + document.getElementById('inputField').value); websocket.send(document.getElementById('inputField').value); } websocket.onmessage = function(e){ output("got response: " + e.data); } function closeSocket(){ websocket.close(); } websocket.onclose = function(){ output("disconnected"); } function output(t){ document.getElementById("output").innerHTML += t + "<br />"; } C# Server: using System; using System.Net; using System.Net.Sockets; namespace WebSocketsTutorial { class Program { static void Main(string[] args) { TcpListener server = new TcpListener(IPAddress.Parse("127.0.0.1"), 80); TcpClient client = default(TcpClient); server.Start(); Console.WriteLine("server started"); while (true) { client = server.AcceptTcpClient(); byte[] receivedBuffer = new byte[100]; NetworkStream stream = client.GetStream(); stream.Read(receivedBuffer, 0, receivedBuffer.Length); foreach (byte b in receivedBuffer) { Console.Write(Convert.ToChar(b).ToString()); } } } } } This is what is output on the console when the client connects: What I'm mainly looking to do is to allow an arbitrary number of connections and ultimately have the server echo a user's submission to all connected clients.
  13. I have an html5 canvas providing a view into a world with a bunch of points. The user can click and drag around to pan the view. I'd like to know if my method here is horribly inefficient and could possibly be optimized another order of magnitude. It's currently a little laggy for me with a million points. jsfiddle: https://jsfiddle.net/3oc1mnu6/2/ HTML: <canvas id="myCanvas" width="960" height="540" style="border:1px solid #000000;"></canvas> Javascript: //world dimensions var worldWidth = 4000; var worldHeight = 3000; //mouse down bool var mouseDown = 0; var canvas = document.getElementById("myCanvas"); var context = canvas.getContext("2d"); //point class function point(x, y){ this.x = x; this.y = y; } //some key points var camera = new point(1000, 1000); var cameraLocationWhenMouseClicked = new point(); var mouseDownLocation = new point(); //the mass of points var numPoints = 1000000; var points = []; for (var i = 0; i < numPoints; i++){ points.push(new point(Math.random() * worldWidth, Math.random() * worldHeight)); } //mouse event handlers canvas.addEventListener("mousedown", mouseDownEventHandler); canvas.addEventListener("mousemove", mouseMoveEventHandler); canvas.addEventListener("mouseup", mouseUpEventHandler); //on mouse down function mouseDownEventHandler(e){ mouseDown = 1; //update mouseDownLocation mouseDownLocation.x = e.offsetX; mouseDownLocation.y = e.offsetY; //store where the camera was when mouse down occurred cameraLocationWhenMouseClicked.x = camera.x; cameraLocationWhenMouseClicked.y = camera.y; } //on mouse move function mouseMoveEventHandler(e){ //if mouse is down if (mouseDown == 1){ //adjust camera location camera.x = cameraLocationWhenMouseClicked.x + (mouseDownLocation.x - e.offsetX); camera.y = cameraLocationWhenMouseClicked.y + (mouseDownLocation.y - e.offsetY); } } //on mouse up function mouseUpEventHandler(){ mouseDown = 0; } function drawScreen(){ //draw canvas context.fillStyle = "white"; context.fillRect(0, 0, canvas.width, canvas.height); //draw points context.fillStyle = "black"; for (var i = 0; i < points.length; i++){ //only draw if in view if((camera.x < points[i].x)&&(points[i].x < camera.x + canvas.width)&&(camera.y < points[i].y)&&(points[i].y < camera.y + canvas.height)){ context.fillRect(points[i].x - camera.x, points[i].y - camera.y, 1, 1); } } } window.setInterval(drawScreen);
  14. Adjust angle towards another angle

    Yep it's clear. Euler's formula traces a unit circle in the complex plane. I'll have to implement a complex class and overload some arithmetic operators for it. That should be fun and useful though. Thanks for the help sir.
  15. Adjust angle towards another angle

    Is the complex just a mapping of (real, imaginary) -> (x, y) for this case?
  • Advertisement