首页 \ 问答 \ 处理C中的动态整数类型?(Dealing with dynamic integer types in C?)

处理C中的动态整数类型?(Dealing with dynamic integer types in C?)

我正在用C开发一个Python模块,它解析一个使用动态整数大小的非常有效的协议。 使用此协议发送的整数的大小范围可以从C的“short”到“long long”。

该协议有一个字节,指定发送的变量类型(从短到长),但我不知道如何在代码中处理这个。 现在,我正在设置一个void指针,并按照发送的值的大小分配内存 - 然后使用atoi,atol和atoll设置该指针。 问题是,我需要能够访问该值,并且如果不在以后进行转换,则无法执行此操作。

有什么好方法可以解决这个问题?


I'm developing a Python module in C that parses a very efficient protocol which uses dynamic integer sizes. Integers sent using this protocol can range in size from the equivalent of C's 'short' to a 'long long.'

The protocol has a byte that specifies the type of variable being sent (from short to long long), but I'm not sure how to deal with this in code. Right now, I'm setting up a void pointer and allocating memory in the size of the value being sent -- then using atoi, atol, and atoll to set that pointer. The problem is, I need to be able to access that value, and am unable to do so without it being cast later.

What are some good ways to handle this issue?


原文:https://stackoverflow.com/questions/2308666
更新时间:2023-03-07 07:03

最满意答案

得到它了。 在我加载它的位图(从房间里)之后,我将太空船添加到了房间。

    //Load The Level******************************
    //Create a new room
    room = new Room(800,600, 0);
    //Load game objects
    SpaceShip user = new SpaceShip();
    **//Load sprites
    for(int i=0;i<room.numberOfGameObjects;i++) {
        room.gameObjects[i].spriteGLIndex = room.gameObjects[i].loadSprite(context, room.gameObjects[i].spriteResId);   
    }
    //Add them to the room
    room.addGameObject(user);**
    //********************************************

Got it. I added the spaceship to the room AFTER I loaded it's bitmap (from the room).

    //Load The Level******************************
    //Create a new room
    room = new Room(800,600, 0);
    //Load game objects
    SpaceShip user = new SpaceShip();
    **//Load sprites
    for(int i=0;i<room.numberOfGameObjects;i++) {
        room.gameObjects[i].spriteGLIndex = room.gameObjects[i].loadSprite(context, room.gameObjects[i].spriteResId);   
    }
    //Add them to the room
    room.addGameObject(user);**
    //********************************************

相关问答

更多
  • 我认为你应该为其他原语使用一个新的着色器。 两条小评论: 您是否考虑使用小纹理(包含圆圈)而不是像这样进行计算? 它可能会快一点,但显然取决于细节。 还要尽量避免使用discard关键字。 它可能会对性能产生负面影响。 例如,您可以为当前丢弃的片段将alpha值设置为0。 I think you should just use a new shader for other primitives. Two minor comments: Did you consider using a small textu ...
  • 好的,我到底了。 我将列出一般要检查的东西,以防万一有人再次来到这里,那么我的损坏究竟是什么。 一般来说: 1)如果你没有看到东西,请关闭剔除面( glDisable(GL_CULL_FACE) ); 这样,如果你的多边形的手性方向错误,你仍会看到一些东西。 2)请注意,OpenGL的0,0是左下角,但你可能已经确定0,0是你的UI代码的左上角(这可以帮助和教你三角形的错误用法)。 这里第13点显示了如何避免这种情况。 3)如果你在屏幕上看到垃圾,你可能忘记清除你的缓冲区了。 所以,具体来说,我有一些错误的 ...
  • 得到它了。 在我加载它的位图(从房间里)之后,我将太空船添加到了房间。 //Load The Level****************************** //Create a new room room = new Room(800,600, 0); //Load game objects SpaceShip user = new SpaceShip(); **//Load sprites for(int i=0;i
  • 你可以在这里查看GlSurfaceView的源代码(它也可以在你机器上安装的sdk中的某个地方),可以在这里找到文档。 相关的信息位是在您调用SetRenderer一次之后,之后不允许您调用以下内容: SetRenderer(第二次) setEGLContextFactory setEGLWindowSurfaceFactory setEGLConfigChooser setEGLContextClientVersion 您发布的代码并未显示您已完成的操作,但我认为您可能在未发布的代码中调用其中一个函数。 ...
  • 通过阅读本文和此 ,可以构建混合函数。 由于您使用的是glBlendFunc而不是glBlendFuncSeparate ,因此所有4个通道都在混合使用。 使用GL_FUNC_ADD参数将输出O设置为O = sS + dD ,其中s和d是混合参数, S和D是源颜色和目标颜色。 s和d参数由glBlendFunc设置。 GL_ONE将s设置为(1, 1, 1, 1) GL_ONE_MINUS_SRC_ALPHA (1, 1, 1, 1) , GL_ONE_MINUS_SRC_ALPHA将d设置为(1-As, ...
  • 你有几种选择,最理想的取决于你的情况。 一些可能性: 编写一个着色器,它不对纹理进行采样,并使用它直到您的纹理流入并准备就绪。 创建一个“空白”纹理,并将其绑定到相应的槽,直到您创建真实纹理。 然后,切换绑定。 与#2相同,但您可以改为更新空白纹理,并且不需要切换绑定。 You have several options here, the most desirable depends on your situation. Some possibilities: Write a shader, which d ...
  • OpenGL ES 2.x与OpenGL ES 1.x不向后兼容。 您必须编写不同的代码来支持它们。 OpenGL ES 2.x is not backward compatible with OpenGL ES 1.x. You have to write different code to support both of them.
  • 仔细阅读之后,结果表明我所要做的就是修改清单文件中的活动。 问题解决了。 After reading carefully through that, turns out all i had to do was modify the activity in the manifest file. Problem Solved.
  • 要使用OpenGL-ES在PC上进行开发,我建议您尝试将OpenGL-ES调用转换为Direct3D的ANGLE 。 它已经非常成熟,因为它被Firefox和Chrome用于WebGL,用于解决某些供应商在Windows上的OpenGL驱动程序问题。 对于Android,您可以查看Android NDK和NVidia Tegra示例代码 ,它们只会向您显示您的要求。 To develop on PC using OpenGL-ES, I'd recommend you to give a try to AN ...
  • 我找到了答案: 当我加载纹理时,我没有正确地将它传递给OpenGL。 我添加了TextureLoader.loadTexture一个GLES20.glBindTexture(GLES20.GL_TEXTURE_2D,texture [0]); 像这样的行: ... Bitmap tex = BitmapFactory.decodeResource(context.getResources(), resource, bo); GLES20.glBindTexture(GLES20.GL_TEXTURE ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。