# Basiror

Member

2689

1. ## bicubic interpolation on image enlargements

Hi I am trying to implement a few image resizing algorithms into my library I know how bicubic reducing works you calculate the destination pixel from the bicubic weights of a 4x4 pixel field around the nearest pixel coordinate in the source image [a href="http://astronomy.swin.edu.au/~pbourke/colour/bicubic/"]becubic interpolation[/a] my problem is how can i enlarge the image e.g.: having a 32*32 image and scale it to 256*256 in order to enlarge i would calculate the 4x4 pixel values out of the 32*32 image and write them to the 256*256 image but in order to do this i hade to interatively rescale 32*32->64*64->128*128->256*256 or is there a simpler solution e.g.: when i downscale i use a 4x4 field so 64*64->32*32 using 4x4 and 256x256->32*32 using a 64x64 field? so i had to distribute one pixel of the 32*32 image to a 64x64 field in the 256*256 image? any idea on how to do this correctly?

5. ## [web] JSP Servlets and eventqueue

The world isn t always as easy as it seams. The reason I use the approach with an event queue is that I need to guarantee the in order execution. How would you handle all these events otherwise? when the user refreshes his page? Thats even worse because you unevenly distribute the work over time leading to spikes with lot of work to do. Imagine a user has 1000 events since his last refresh, you had to handle all these events before you return the latest state . At peak times this will make your game unplayable. My archtecture will run pretty smoothly even at peak times since it distributes work over time. And parsing a few hundred strings costs you nothing. The other advantage of event queues is, you can split them depending on their locality. Fights taking place in the other half of your game world could be placed in a second event queue effectively halving the work one update process has to perform. With your setup you have to trigger state updates by user actions which is no option. All browsergames I know of (space battle games...) use some sort of externally triggered update mechanism.
6. ## [web] JSP Servlets and eventqueue

Hello, I need some advice from experienced web developers. Currently I am working on a browser game using hybrid technology. This is I got a MySQL server, a C++ application and tomcat+jsp It the whole system as follows. client ->JSP -> encode commands as strings -> MySQL command queue(just a innodb table) MySQL command queue -> decode commands -> C++ App -> update MySQL database MySQL database -> JSP -> client(some browser) The problem is the last step, I need to guarantee it is executed after the C++ has updated the MySQL database, otherwise the refreshed page would contain old information and I had to refresh once again. I see only two options a) using AJAX set some timer and then load the actual page content b) since each servlets a threaded, I had to sleep/schedule the servlet thread some time maybe 500 ms a) is an elegant solution but involved a lot of more work and you need javascript on the client side b) on the other hand delaying the servlet is a simple and effective solution What do you think which way should I go?
7. ## [web] JSP Servlets and eventqueue

Why not? I am not using C++ to generate the webpages, thats done with java servlets JSP JSTL ... The C++ backend just reads in the command queues and handles all the game logic. I see no reason not to use C++ there. C++ is my prefered language anyways. Anyways I decided to use Ajax to load the page content with a tiny delay of 50-100 ms.
8. ## Windows vs. Ubuntu

Quote:Original post by swiftcoder Quote:Original post by Basiror That is "bash" + "vim". I usually open several( around 10) tabs in the bash, with each running vim showing some files.Have you discovered that vim itself sports graphical (and mouse enabled) tabs? [wink] Not yet, thats just awesome, makes me even more prouctive with vim. One more reason not to use Visual Studio. Is there a away to store the tab configuration upon closing?
9. ## Windows vs. Ubuntu

I also have to say my few cents here. Earlier I have been working on Windows (Visual Studio ...), during my the first semesters at university I switched to linux and up until now I seen no reason to switch back to windows anytime in the future. Why? I just found the perfect development environment for my purpose. That is "bash" + "vim". I usually open several( around 10) tabs in the bash, with each running vim showing some files. I can work on my programming projects for hours without even touching the mouse. Switching to linux makes no sense for me if you indent to use GUI applications for development, thats the strength of Windows in conjunction with Visual Studio. However, if you are willing to dive into the world of bash+vim you should be prepared to having to learn the mechanics, which have a steep learning curve. I usually takes years in order to find out all the little tricks involved. I consider my self a linux newbie after more than 5 years, there are a lot of very very useful features I haven t touched already, that would boost my productivity. My personal experience is, that is way less cumbersome to work with bash+vim than it is to use all these GUI front ends. Just be prepared, its not that easy to just switch to linux, you will need several years. Just my experience. No rant here.
10. ## Octree - Raytracing & voxel iteration

Rendering the primary rays with the GPU is certainly an option, but I d try 8x8 sub sampling first, that is ray tracing only 1.56% of the required rays Also make sure to calculate nearby rays in a sequence in order to improve cache coherency

12. ## SDL or SFML?

I had a look at the features of SFML and am very impressed, it reallys saves you a lot of work and contains nearly everything you need to get started, network, graphics, cpGUI, ... I ll give it a try for my upcoming project
13. ## how far to translate during md5 animation

usually the root node stays at its start location when animating some model. Just animate the legs of your walkanimation relative to its root, so you don t have to mess around with changing root nodes' position. In order to get a smooth animation you need to calculate at a fixed animation framerate of e.g. 32 hz how far the actor can travel given its step size(depends on your model), e.g. at frame 16 the model traveled X units( half a step) at 32 it will have traveled 2X units Now calculate based on the constant movement speed of your actor the time t in [0.0,32.0] that represents the actual keyframe of your animation. ti = floor(t) ti+1 = ceil(t)
14. ## Best SDL GUI library?

I just want to throw in guichan, it is written in c++ and pretty easy to use.
15. ## [GCC 4.2.3] std::sort bug

Hello, I think I spotted a bug in std::sort or my GCC binary On Ubuntu Hardy 8.04: Using built-in specs. Target: x86_64-linux-gnu Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 4.2.3 (Ubuntu 4.2.3-2ubuntu7) Running the following code gives me a wrong output: Compiled with g++ -o huffman main.cpp main.cpp 1 #include "huffman.h" 2 3 int main( int argc, char** argv) 4 { 5 std::vector< unsigned int> symbols; 6 symbols.push_back(1); 7 symbols.push_back(2); 8 symbols.push_back(3); 9 symbols.push_back(4); 10 symbols.push_back(2); 11 symbols.push_back(2); 12 symbols.push_back(1); 13 14 const Node* root = BuildHuffmanTree(symbols); 15 root->Print(); 16 return 0; 17 }; huffman.h 1 #ifndef HUFFMAN_H 2 #define HUFFMAN_H 3 #include <deque> 4 #include <vector> 5 #include <algorithm> 6 #include <iostream> 7 #include <iterator> 8 9 typedef unsigned int uint; 10 typedef std::vector< uint > SymbolVector; 11 12 class Node 13 { 14 public: 15 typedef std::deque< Node* > Queue; 16 public: 17 const uint weight; 18 SymbolVector symbol; 19 const Node* left; 20 const Node* right; 21 public: 22 Node(const uint _weight, const uint _symbol) : weight(_weight),symbol(1,_symbol),left(0),right(0) {}; 23 Node(const Node* _left, const Node* _right) 24 : 25 weight(_left->weight + _right->weight), 26 left(_left),right(_right) 27 { 28 symbol.insert(symbol.end(),left->symbol.begin(),left->symbol.end()); 29 symbol.insert(symbol.end(),right->symbol.begin(),right->symbol.end()); 30 }; 31 void Print() const 32 { 33 std::ostream_iterator<uint> ot(std::cout,", "); 34 std::copy(symbol.begin(),symbol.end(),ot); 35 std::cout<<"weight: "<<weight<<std::endl; 36 if(left) left->Print(); 37 if(right) right->Print(); 38 }; 39 }; 40 41 inline const bool queue_pred(const Node* a, const Node* b) 42 { 43 return a->weight < b->weight; 44 }; 45 46 inline const Node* BuildHuffmanTree(const SymbolVector& csymbols) 47 { 48 SymbolVector uniquesymbols(csymbols); 49 std::sort(uniquesymbols.begin(),uniquesymbols.end()); 50 51 std::ostream_iterator<uint> ot(std::cout,", "); 52 std::copy(uniquesymbols.begin(),uniquesymbols.end(),ot); 53 { 54 SymbolVector::iterator i = std::unique(uniquesymbols.begin(),uniquesymbols.end()); 55 uniquesymbols.resize(uniquesymbols.end()-i); 56 } 57 std::cout<<uniquesymbols.size()<<std::endl; 58 Node::Queue queue; 59 60 for(SymbolVector::iterator i=uniquesymbols.begin();i!=uniquesymbols.end();++i) 61 { 62 const uint weight = std::count(csymbols.begin(),csymbols.end(),*i); 63 queue.push_back( new Node(weight,*i) ); 64 } 65 66 while(queue.size() > 1) 67 { 68 std::sort(queue.begin(),queue.end(),queue_pred); 69 const Node* left = queue.front(); queue.pop_front(); 70 const Node* right = queue.front(); queue.pop_front(); 71 queue.push_back( new Node(left,right) ); 72 } 73 74 const Node* result = queue.front(); 75 return result; 76 }; 77 78 79 #endif The output is: ./huffman 1, 1, 2, 2, 2, 3, 4, 3 2, 3, 1, weight: 6 2, weight: 3 3, 1, weight: 3 3, weight: 1 1, weight: 2 the first line should be: 1, 1, 2, 2, 2, 3, 3, 4, So either I did something wrong in my code or I just discovered a bug. Could some of you try to compile this source snipped and compare the results? Please also provide information about your compiler and OS. thx in advance.
16. ## [GCC 4.2.3] std::sort bug

Oh yeah, it was my fault, but it was late at night so :) thx for your help anyways Maybe some moderator could delete this thread?
17. ## Randomizing array function - need explanation for 1 line

The index is at at atleast "i" + some offset offset = rand()%(52-1); the offset+i must be below 52, thats why it is 52-i 0+offset 52-0 1+offset 52-1 ... as Sneftel already mentioned, they increment the base index i each iteration to avoid inversion of previous permutations, with the worst case scenario of no permutation at all.

20. ## Multithreaded MMO Engine Design

Quote:Original post by elFarto Quote:Original post by Basiror ...but I decided to go the data duplication way I went down this route, except I went mad and developed my AtomicDatabase, a transactional lock-free(ish) database. This way I don't have to care about the rest of the design, I know each transaction will see a consistent view of the world. My entity design is a simple class with each field wrapped by a VersionedValue (the main class in my atomic database), all generated from an XML file. Regards elFarto The problem is, if for example your physics engine changes the object's position and the culling system is working with the old position you have no way to detect this. a) make a copy of the old position to be used through out this frame b) somehow signal the scenegraph to reinsert this object c) or defer the application of variable changes one frame You could implement connectors to simulate access rights to objects to avoid modification by the multiple threads during the same frame# e.g.: ComponentSharedData data; PhysicsComponent: ref<SomeType> position(data.Get("position")); Renderable: const_ref<SomeType position(data.Get("position")); ref<> and const_ref<> this only grants the PhysicsComponent write access to "position", but sometimes it is desireable to grant multiple components write access, for example if you implement a spell "teleport" using the Job system I described earlier. One solution would be to: // stage 2 where all jobs are handled const SomeType reset() { return 0; }; Job: ref<SomeType> offset(data.Get("offset)); // add a callback, we only want to teleport onces offset.onread = reset; offset = newposition; // stage 3 during application and hierarchy rebuilding, thus no more writes from stage 2 threads, thus no locking PhysicsComponent: ref<SomeType> offset(data.Get("offset")); position += offset; //executes offset.onread and resets it

22. ## Inviting programmers for an Open Source project

please move this to the help wanted forums and use the mandatory posting template
23. ## Ray and Rectangle Collision

Hello, have a look at line clipping http://en.wikipedia.org/wiki/Line_clipping that should get you started
24. ## GPU Ray Casting against Triangles - help to understand

CUDA can interoperate with D3D and you have access to pointers and you can read and write to memory, with HLSL you are bound to write to a limited number of render targets, whereas CUDA allows you to write to some arbitrary memory that you have allocated, which allows you to use many targets as you wish. This greatly simplifies the calculation of child rays. For each ray intersection you insert a couple of children rays into a list managed by the current CUDA thread (on the GPU) and pre sort them This is familiar with a merge sort, it first splits up the list into tiny lists of 2 elements, sorts them according to some metric and merges them back. The merge could then be applied to ray lists. Lets say you have 4000 rays and each ray spawns 10 children, so you allocate memory for a) the color buffer to output the ray's contribution b) a buffer to store < numrays * rays> If you don t spawn a ray you need to mark each possible ray in the list as invalid and make sure its placed at the end of your sorted ray array according to your metric The case that you have hit nothing with a ray could be handled by inserting the current ray at the top of the ray list and mark the rest as invalid There are parallel versions of merge sort, worth a look. Thus all you do on the CPU is 1. run one pass (new rays presorted at the end) 2. merge the sorted lists into one huge buffer 3. examine the the ray buffer to load the required data sets onto the GPU repeat 1 until some convergency criteria is fulfilled What you need is a hierarchical data structure that you traverse with each ray and the results are evaluated on the CPU to stream in the appropriate data chunks to preceed Have a look at this paper, they are doing ray tracing of volume datasets, but the technique of traversion of the hierarchy is identical. http://artis.imag.fr/Publications/2009/CNLE09/
25. ## GPU Ray Casting against Triangles - help to understand

I highly recommend you to use CUDA::drivers API look at the CUDA programming guide its far easier than messing around with GLSL. Also be aware that only the primary and maybe the secondary rays can be cast efficiently on the GPU, all other rays require you to resort them on the CPU to ray bundles, but I guess you have read this up already