Allegro.cc - Online Community

Allegro.cc Forums » The Depot » [SH15] The Human CPU Experiment

Credits go to amarillion, Bruce Pascoe, devo_au, Edgar Reynaldo, Elias, GullRaDriel, Mark Oates, Peter Hull, and SiegeLord for helping out!
This thread is locked; no one can reply to it. rss feed Print
 1   2 
[SH15] The Human CPU Experiment
GullRaDriel
Member #3,861
September 2003
avatar

up, up, up ?
then print the number of byte it tried to malloc ?

Edit: you didn't ran it through the debugger ?

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Bruce Perry
Member #270
April 2000

Gull, are you mixing it up with Elias's entry where we found out that a calloc failed?

Edgar seems to be the stalwart SpeedHack crasher this year :-/ I would suggest some asm-level debugging, but it's obviously up to Edgar how much insanity he's willing to take :)

--
Bruce "entheh" Perry [ Web site | DUMB | Set Up Us The Bomb !!! | Balls ]
Programming should be fun. That's why I hate C and C++.
The brxybrytl has you.

GullRaDriel
Member #3,861
September 2003
avatar

Yeah, you're right about the mixing up Bruce ^^

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Bruce - if you can help me get a working D compiler set up I can try to build it myself, but I have zero experience with D so you'd have to guide me through it. Also, how should I debug it without Visual D? Or does Visual D support MSVC 2010? That's the latest version I can install on my Vista laptop.

Bruce Perry
Member #270
April 2000

OK, first thing I should say is, I'm in Germany with a laptop that doesn't have any of this set up. I'm flying home tomorrow evening, and I'm wondering if there's a PDB sitting at home that I could share with you first before we start trying to set up an environment. I'll be able to check for that on Saturday (or maybe Friday last thing).

If you do want to start setting stuff up, then:

Get D from http://dlang.org/download.html - it has an installer. I installed it in C:\D, and ended up with a compiler in C:\D\dmd2\bin (which is worth adding to the path). If you get a choice, don't bother with D v1 - just take D v2.

DAllegro5 is best git-cloned from https://github.com/SiegeLord/DAllegro5 . You will need the 5.1 branch, since I used 5.1 features (ALLEGRO_PROGRAMMABLE_PIPELINE). You will then need to go into DAllegro5/allegro5/base.d and tweak the version to match whichever version of Allegro you have. After that SiegeLord has instructions for building DAllegro5 (see https://github.com/SiegeLord/DAllegro5/tree/5.1), but I had dashes in my path and found them a bit temperamental and had to tweak them. It also needs tweaking if you have monolith DLLs since the names don't match up.

As for Visual D, I believe it does support MSVC 2010, but you will need a version of MSVC 2010 that supports plugins. In terms of free versions, I think there is an 'express' edition which WON'T work, and there is a 'shell' edition which WILL work (it allows plugins but comes without C/C++ or any other language support built in).

I think I included the Visual D project files in the zip, but I used global settings (not project settings) to specify where DAllegro5's .d files and .lib files can be found. You'll need to do the same. For the .d files, you need to specify an 'import' directory - it's a bit like an include directory. You may need to get rid of DAllegro5's example.d file (although it's possible I only had a problem with this when I had my own copy of it in my project).

It's a lot, I know :-/

[EDIT + BUMP]
I just got a score of E3C5. Data isn't safe for ever :)

Edgar, I've attached a Debug executable. Any luck with that one?

--
Bruce "entheh" Perry [ Web site | DUMB | Set Up Us The Bomb !!! | Balls ]
Programming should be fun. That's why I hate C and C++.
The brxybrytl has you.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

This is the only output. gdb still doesn't recognize it as an executable, and MSVC 2010 can't open it.

Quote:

c:\ctwoplus\progcode\allegro5\SpeedHack2015entries\HumanCPU>HumanCPUdebug.exe
object.Error@(0): Access Violation
----------------
Press Enter to close

c:\ctwoplus\progcode\allegro5\SpeedHack2015entries\HumanCPU>

GullRaDriel
Member #3,861
September 2003
avatar

Maybe your antivirus is blocking it ?

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Bruce Perry
Member #270
April 2000

Come to think of it, I think this may be an outstanding issue with D that I've hit before: no stack traces on access violations. I remember having to step through it with the debugger to find out where the bug was. Obviously that's not presenting itself as an option for you at the moment.

Try the attachment. I opened it with VS 2010 Shell and built it from scratch. You will probably need to install Visual D (which is really easy), but you hopefully won't need anything else D-related. Once you've done that, open up main.d and set a breakpoint on the very first non-import line: "int main(string[] argv) {". Set another breakpoint on "return main2();" because the stupid thing won't single-step properly into al_run_allegro. Then run it, single-stepping as you go, and see how far it gets, I guess? Another thing you can try is the Disassembly window; for me, it intersperses it with source code so you can make sense of it pretty easily, and it helps you sidestep those cases where single-step doesn't work properly.

--
Bruce "entheh" Perry [ Web site | DUMB | Set Up Us The Bomb !!! | Balls ]
Programming should be fun. That's why I hate C and C++.
The brxybrytl has you.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

I can't install Visual D properly because I'm using an Express Edition of 2010. It won't integrate with VS in the installation.

Edit

Try the attachment. I opened it with VS 2010 Shell and built it from scratch.

Where did you get the VS 2010 Shell from?

Bruce Perry
Member #270
April 2000

It was a download once upon a time. Looks as if MS have discontinued it :(

I found my copy of the download. Give it a try. [EDIT: finally finished uploading!]

--
Bruce "entheh" Perry [ Web site | DUMB | Set Up Us The Bomb !!! | Balls ]
Programming should be fun. That's why I hate C and C++.
The brxybrytl has you.

Peter Hull
Member #1,136
March 2001

Got it running on Mac, not without a few issues in D to do with int <-> ulong conversions and also a problem with the shaders. (more detail tomorrow, I'm off to bed now)
Nice one!
Pete
{"name":"609587","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/1\/f1ef09206c7d404250dfbef873746651.png","w":819,"h":640,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/1\/f1ef09206c7d404250dfbef873746651"}609587

Onewing
Member #6,152
August 2005
avatar

Excellent entry, love the way it deforms and raises concern per every wrong answer. Definitely the most intense of the 2015 entries. Would've love some way to skip questions (perhaps a collectible item if you can answer within a second or something)...but computers don't skip questions. :D

------------
Solo-Games.org | My Tech Blog: The Digital Helm

Peter Hull
Member #1,136
March 2001

These are the only diffs I had to make for it to run on OS X.

#SelectExpand
1diff --git a/game.d b/game.d 2index eb06529..779e66c 100644 3--- a/game.d 4+++ b/game.d 5@@ -21,7 +21,7 @@ Ready 6 Set 7 Go!!! 8 `; 9-int introPos; 10+ulong introPos; 11 int introDelay; 12 char[] currentAnswer; 13 bool inputActive; 14diff --git a/questions.d b/questions.d 15index 9247646..b6dc447 100644 16--- a/questions.d 17+++ b/questions.d 18@@ -153,9 +153,9 @@ bool answerIsRight(const(char)[] answer) { 19 } 20 21 int questionRange() { 22- int r = 1 + questionCount / newQuestionTypeEvery; 23+ ulong r = 1 + questionCount / newQuestionTypeEvery; 24 if (r > questionGenerators.length) r = questionGenerators.length; 25- return r; 26+ return cast(int) r; 27 } 28 29 auto questionGenerators = [ 30diff --git a/shaders.d b/shaders.d 31index 2a049c9..b364e5e 100644 32--- a/shaders.d 33+++ b/shaders.d 34@@ -26,9 +26,8 @@ uniform bool ` ~ ALLEGRO_SHADER_VAR_USE_TEX ~ `; 35 varying vec4 varying_color; 36 varying vec2 varying_texcoord; 37 void main() { 38- ivec2 ts = textureSize(` ~ ALLEGRO_SHADER_VAR_TEX ~ `, 0); 39- float yf = fract(varying_texcoord.y * ts.y) - 0.5; 40- float brightness = 1.5 - abs(yf)*2; 41+ float yf = fract(varying_texcoord.y * 55.0); 42+ float brightness = yf * (1.0 - yf) * 4.0; 43 if (` ~ ALLEGRO_SHADER_VAR_USE_TEX ~ `) 44 gl_FragColor = varying_color * texture2D(` ~ ALLEGRO_SHADER_VAR_TEX ~ `, varying_texcoord) * brightness; 45 else

It looks like .length is a ulong on my platform, not an int, so I put in some casts.
On the shader, AFAICS textureSize isn't supported. I know absolutely nothing about GLSL, googled a bit and it seemed to be that OSX gives you OpenGL 2.x by default unless you ask for a "core profile". Maybe someone who understands OpenGL can make sense of that. Also it seemed to complain about multiplying ints by floats, in "varying_texcoord.y * ts.y" and also "abs(...) * 2".

Cheers,
Pete

Bruce Perry
Member #270
April 2000

Thanks for getting it working on the Mac :)

Does abs not exist? I'd have expected you could just change it to "abs(yf)*2.0"? I started with the same quadratic formula you have there, but it didn't give a consistent brightness as I scaled the resolution, which is why I took the linear approach with 'abs'.

Your screenshot looks a bit wonky in another way too: different rows of characters get their scanlines done differently. I'm going to guess that the texture actually has powers of two for dimensions (why textureSize is so important); you could probably fix it on your system by writing 64 instead of 55, but I wouldn't trust it as a general fix.

So in summary, you could try this code if you want:

-  ivec2 ts = textureSize(` ~ ALLEGRO_SHADER_VAR_TEX ~ `, 0);
-  float yf = fract(varying_texcoord.y * ts.y) - 0.5;
-  float brightness = 1.5 - abs(yf)*2;
+  float yf = fract(varying_texcoord.y * 64.0) - 0.5;
+  float brightness = 1.5 - abs(yf)*2.0;

I can't say I've ever heard of a 'core profile' - perhaps it's an Apple thing?

Onewing said:

Excellent entry, love the way it deforms and raises concern per every wrong answer. Definitely the most intense of the 2015 entries. Would've love some way to skip questions (perhaps a collectible item if you can answer within a second or something)...but computers don't skip questions. :D

You can sort of skip questions, because when you get one wrong, it increases a variable called 'severity', and when you get one right, it decreases it again. As long as you get some right after the one you got wrong, nothing is lost (except that difficulty has still progressed a bit and you missed out on the points for that question). :)

--
Bruce "entheh" Perry [ Web site | DUMB | Set Up Us The Bomb !!! | Balls ]
Programming should be fun. That's why I hate C and C++.
The brxybrytl has you.

Peter Hull
Member #1,136
March 2001

I tried a lot of different things to get it to work (as has been mentioned, debugging D seems ... challenging) so the screen shot doesn't necessarily correspond to the code (see below for what it does look like). I thought the quadratic looked better to my eyes. You're right, abs does exist, I will change it.
609609

Bruce Perry
Member #270
April 2000

The 9000 isn't a perfect test because all those glyphs came from the same row of the png, but the scanlines do seem to match up with the pixels, so it's probably correct with whatever you have now (55 or 64) :)

By the way, in case you wondered, the slight saturation effect (where it goes too bright to represent and the green gets clamped while the red and blue don't) is deliberate. It makes it look a little more interesting than if everything is perfectly one colour.

--
Bruce "entheh" Perry [ Web site | DUMB | Set Up Us The Bomb !!! | Balls ]
Programming should be fun. That's why I hate C and C++.
The brxybrytl has you.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Bruce - no success yet, but perhaps progress.

I'm trying to compile Allegro 5.1.11 to use with DAllegro5 so I can compile your human cpu project, but it barfs on trying to make an MSVC 2010 project. What version of Allegro does your program need to compile? I can get binaries for 5.0.10 if that works. Okay I have the 5.0.10 binaries in a folder called c:\msvc\, but I haven't the faintest idea how to configure a VS project to link to allegro, and I don't know how to get the DAllegro5 example to build either.

Bruce Perry
Member #270
April 2000

Sorry I haven't replied for so long. Only just had a chance to look here!

It does unfortunately need 5.1.x.

I wonder if this zip will help? It includes a built version of Allegro 5.1.x, and built versions of all the D libs corresponding to Allegro's DLLs. I also included my txt file with lots of instructions, most of which you won't need to follow, but it includes a bit of stuff about how to configure the IDE (you can ignore the Derelict bits since I didn't use that for this game). If you want to use the prebuilt stuff in here, you may be best obtaining D v2.066.0, since the more versions newer you go, the more likely those libs are to be incompatible. (I apologise - the zip is still uploading. Give it half an hour maybe. I just checked and it's 404ing until it's ready, so you won't get a broken file.)

--
Bruce "entheh" Perry [ Web site | DUMB | Set Up Us The Bomb !!! | Balls ]
Programming should be fun. That's why I hate C and C++.
The brxybrytl has you.

 1   2 


Go to: